Exemplo n.º 1
0
        public void WhenKilometersNone_ShouldEqualZeroKilomters()
        {
            // Act
            var actual = Kilometer.None;

            // Assert
            actual.Should().Be(Kilometer.FromDecimal(0));
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            _distance1InDecimals = _fixture.Create <decimal>() * _fixture.Create <decimal>();
            _distance1           = Kilometer.FromDecimal(_distance1InDecimals);

            _distance2InDecimals = _fixture.Create <decimal>();
            _distance2           = Kilometer.FromDecimal(_distance2InDecimals);
        }
Exemplo n.º 3
0
        public void WhenSubtracting_ResultShouldBeDistanceMinusOtherDistance()
        {
            // Act
            var actual = _distance1 - _distance2;

            // Assert
            var expected = Kilometer.FromDecimal(_distance1InDecimals - _distance2InDecimals);

            actual.Should().Be(expected);
        }
Exemplo n.º 4
0
        public void WhenAdding_ResultShouldBeSumOfDistances()
        {
            // Act
            var actual = _distance1 + _distance2;

            // Assert
            var expected = Kilometer.FromDecimal(_distance1InDecimals + _distance2InDecimals);

            actual.Should().Be(expected);
        }
Exemplo n.º 5
0
        public void WhenSameInstance_ShouldBeEqual()
        {
            // Arrange
            var instance = Kilometer.FromDecimal(_distance);

            // Act
            var actual = instance.Equals(instance);

            // Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 6
0
        public void WhenDistanceProvided_ShouldDisplayDistanceAsKilometers()
        {
            // Arrange
            var distance = _fixture.Create <decimal>();

            // Act
            var actual = Kilometer.FromDecimal(distance);

            // Assert
            actual.ToString().Should().Be($"{distance} km");
        }
Exemplo n.º 7
0
        public void WhenDistanceProvided_ShouldSetDistance()
        {
            // Arrange
            var distance = _fixture.Create <decimal>();

            // Act
            var actual = Kilometer.FromDecimal(distance);

            // Assert
            actual.ToDecimal().Should().Be(distance);
        }
Exemplo n.º 8
0
        public void WhenNegativeDistance_ShouldThrowArgumentException()
        {
            // Arrange
            var negativeDistance = -1 * _fixture.Create <decimal>();

            // Act
            Action act = () => Kilometer.FromDecimal(negativeDistance);

            // Asset
            act.Should().Throw <ArgumentException>("Distance must be bigger than 0 km.");
        }
Exemplo n.º 9
0
        public void WhenDifferentDistance_ShouldNotBeEqual()
        {
            // Arrange
            var instance1 = Kilometer.FromDecimal(_distance);
            var instance2 = Kilometer.FromDecimal(_fixture.Create <decimal>());

            // Act
            var actual = instance1.Equals(instance2);

            // Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 10
0
        public void WhenSameDistance_ComparisonShouldBeTrue()
        {
            // Arrange
            var instance1 = Kilometer.FromDecimal(_distance);
            var instance2 = Kilometer.FromDecimal(_distance);

            // Act
            var actual = instance1 == instance2;

            // Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 11
0
        public void WhenCastedToObjectAndSameDistance_ShouldBeEqual()
        {
            // Arrange
            var instance1 = Kilometer.FromDecimal(_distance);
            var instance2 = Kilometer.FromDecimal(_distance);

            // Act
            var actual = instance1.Equals((object)instance2);

            // Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 12
0
        public void WhenDifferentDistances_ComparisonShouldBeTrue()
        {
            // Arrange
            var instance1 = Kilometer.FromDecimal(_distance);
            var instance2 = Kilometer.FromDecimal(_fixture.Create <decimal>());

            // Act
            var actual = instance1 != instance2;

            // Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 13
0
        public void WhenAaaPopulatesEtaField_ShouldDeserializeTheirJsonToKilometers()
        {
            // Arrange
            var httpResponseMessage = _theirResponse.ToHttpResponseMessage();

            // Act
            var actual = _mapper.Map(httpResponseMessage);

            // Assert
            var expected = Kilometer.FromDecimal(_theirResponse.Kilometers);

            actual.Should().Be(expected);
        }
Exemplo n.º 14
0
        public void WhenSameInstance_ComparisonShouldBeTrue()
        {
            // Arrange
            var instance = Kilometer.FromDecimal(_distance);

            // Act
#pragma warning disable CS1718 // Comparison made to same variable
            var actual = instance == instance;
#pragma warning disable CS1718 // Comparison made to same variable

            // Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 15
0
        public void WhenDifferentObjects_ShouldHaveDifferentHashcodes()
        {
            // Arrange
            var distance      = Kilometer.FromDecimal(_fixture.Create <decimal>());
            var otherDistance = Kilometer.FromDecimal(_fixture.Create <decimal>());

            // Act
            var actual1 = distance.GetHashCode();
            var actual2 = otherDistance.GetHashCode();

            // Asset
            actual1.Should().NotBe(actual2);
        }
        public Kilometer Map(HttpResponseMessage responseMessage)
        {
            if (responseMessage.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new ApplicationException($"Failed to get data from AAA service: {responseMessage.ReasonPhrase}");
            }

            var response = responseMessage.Content.ReadAsStringAsync()
                           .GetAwaiter()
                           .GetResult();

            var distanceResponse = JsonConvert.DeserializeObject <GetDistanceResponse>(response);

            return(Kilometer.FromDecimal(distanceResponse.Kilometers));
        }