﻿namespace UtilityBelt.Threading
{
    using System.Security.Policy;
    using FluentAssertions;
    using Xunit;

    public class InterlockedBooleanTests
    {
        [Fact]
        public void When_create_with_default_value_Then_value_should_be_false()
        {
            var sut = new InterlockedBoolean();
            sut.Value.Should().BeFalse();
        }

        [Fact]
        public void When_create_with_value_set_to_true_Then_value_should_be_true()
        {
            var sut = new InterlockedBoolean(true);
            sut.Value.Should().BeTrue();
        }

        [Fact]
        public void When_compare_exchange_and_value_is_same_Then_should_get_original_value_and_set_new_value()
        {
            var sut = new InterlockedBoolean();

            sut.CompareExchange(true, false).Should().BeFalse();
            sut.Value.Should().BeTrue();
        }

        [Fact]
        public void When_compare_exchange_and_value_is_different_Then_should_get_original_value()
        {
            var sut = new InterlockedBoolean();

            sut.CompareExchange(false, true).Should().BeFalse();

            sut.Value.Should().BeFalse();
        }

        [Fact]
        public void Can_set_value()
        {
            var sut = new InterlockedBoolean();

            sut.Set(true);

            sut.Value.Should().BeTrue();
        }
    }
}