public void PrintOrders_GivenCustomerId_ThenGetsOrderIdsAndSendsToOrderPrinter() { // Arrange // fixture creates test data for us var fixture = new Ploeh.AutoFixture.Fixture(); // Substutite creates mock objects for us to interact with var orderServiceMock = NSubstitute.Substitute.For<IOrderService>(); var orderPrinterMock = NSubstitute.Substitute.For<IOrderPrinter>(); // test data var customerId = fixture.Create<CustomerId>(); var orders = fixture.Create<Orders>(); //when GetOrders() called with value equaling customerId, then return orderIds orderServiceMock.GetOrders(customerId).Returns(orders); // "System Under Test" (sut) var sut = new OrderPrintingService(orderServiceMock, orderPrinterMock); // Act sut.PrintOrders(customerId); // Assert orderPrinterMock.Received(1).PrintOrders(orders); }
public async Task GetConfiguration_ShouldReturnCorrectConfiguration_WhenAvailableForEnvironmentTag() { // arrange var key = _fixture.Create <string>(); var version = _fixture.Create <Version>(); var tag = _fixture.Create <string>(); var storedConfigValue = _fixture .Build <StoredConfigValues>() .With(scv => scv.EnvironmentTags, new List <string> { tag }) .Create(); var storedConfig = _fixture .Build <StoredConfig>() .With(sc => sc.Type, _fixture.Create <ValueType>().ToString()) .With(sc => sc.Values, new List <StoredConfigValues> { storedConfigValue }) .Create(); var expectedConfig = new ConfigurationValue { Id = storedConfigValue.Id, Version = version, Sequence = storedConfigValue.Sequence, Data = storedConfigValue.Data, EnvironmentTags = storedConfigValue.EnvironmentTags, CreatedAt = storedConfigValue.CreatedAt }; A.CallTo(() => _repository.GetConfiguration(key, version)) .Returns(storedConfig); // act var config = await _sut .GetConfigurationValue(key, version, tag) .ConfigureAwait(false); // assert config.ShouldBeEquivalentTo(expectedConfig); }
public void When_serialize_should_deserialize_to_equal_objects() { var fixture = new Ploeh.AutoFixture.Fixture(); var product1 = fixture.Create <Article[]>(); var json = JsonConvert.SerializeObject(product1, settings); var product2 = JsonConvert.DeserializeObject <Article[]>(json, settings); var equal = TestUtils.JsonObjectEqualityComparer <Article[]> .Instance.Equals(product1, product2); Assert.True(equal); }