public void WhenKilometersNone_ShouldEqualZeroKilomters() { // Act var actual = Kilometer.None; // Assert actual.Should().Be(Kilometer.FromDecimal(0)); }
public void Initialize() { _distance1InDecimals = _fixture.Create <decimal>() * _fixture.Create <decimal>(); _distance1 = Kilometer.FromDecimal(_distance1InDecimals); _distance2InDecimals = _fixture.Create <decimal>(); _distance2 = Kilometer.FromDecimal(_distance2InDecimals); }
public void WhenSubtracting_ResultShouldBeDistanceMinusOtherDistance() { // Act var actual = _distance1 - _distance2; // Assert var expected = Kilometer.FromDecimal(_distance1InDecimals - _distance2InDecimals); actual.Should().Be(expected); }
public void WhenAdding_ResultShouldBeSumOfDistances() { // Act var actual = _distance1 + _distance2; // Assert var expected = Kilometer.FromDecimal(_distance1InDecimals + _distance2InDecimals); actual.Should().Be(expected); }
public void WhenSameInstance_ShouldBeEqual() { // Arrange var instance = Kilometer.FromDecimal(_distance); // Act var actual = instance.Equals(instance); // Assert actual.Should().BeTrue(); }
public void WhenDistanceProvided_ShouldDisplayDistanceAsKilometers() { // Arrange var distance = _fixture.Create <decimal>(); // Act var actual = Kilometer.FromDecimal(distance); // Assert actual.ToString().Should().Be($"{distance} km"); }
public void WhenDistanceProvided_ShouldSetDistance() { // Arrange var distance = _fixture.Create <decimal>(); // Act var actual = Kilometer.FromDecimal(distance); // Assert actual.ToDecimal().Should().Be(distance); }
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."); }
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(); }
public void WhenSameDistance_ComparisonShouldBeTrue() { // Arrange var instance1 = Kilometer.FromDecimal(_distance); var instance2 = Kilometer.FromDecimal(_distance); // Act var actual = instance1 == instance2; // Assert actual.Should().BeTrue(); }
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(); }
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(); }
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); }
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(); }
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)); }