public void DbContextBuilderWithAutoFixture_GetLast5CustomersWithOrders_HasCorrectCount()
        {
            var dbContextBuilder = new DbContextBuilder();
            var fixture = new Ploeh.AutoFixture.Fixture();

            //Arrange
            dbContextBuilder.Customers = fixture.Build<Customer>()
                .Without(c => c.Orders)
                .CreateMany(2)
                .ToList();

            dbContextBuilder.Customers[0].Orders = fixture.Build<Order>()
                .With(o => o.Customer, dbContextBuilder.Customers[0])
                .With(o => o.Order_Date, DateTime.Now.AddDays(-1))
                .Without(o => o.Order_Details)
                .Without(o => o.Employee)
                .Without(o => o.Shipper)
                .CreateMany(3)
                .ToList();

            IDbContext dbContext = dbContextBuilder.BuildDbContext();

            //Act
            var customerService = new CustomerService(dbContext);
            int customersCount = customerService.GetLast5CustomersWithOrders().Count();

            Assert.That(customersCount, Is.EqualTo(1));
        }
 public ConfigurationStoreServiceTests(
     IConfigurationRepository repo,
     ConfigurationStoreService sut)
 {
     _fixture    = new Fixture();
     _repository = repo;
     _sut        = sut;
 }
        public IEnumerable<object[]> GetParameters(MethodInfo method)
        {
            IFixture fixture = new Fixture();

            CustomizeAutoFixture(fixture);

            yield return GetParameterValues(method.GetParameters(), fixture);
        }
        public IEnumerable<object[]> GetParameters(MethodInfo method)
        {
            IFixture fixture = new Fixture();

            CustomizeAutoFixture(fixture);

            yield return GetParameterValues(method.GetParameters(), fixture);
        }
示例#5
0
        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);
        }
示例#6
0
        public void ToString_GivenPropertyChain_ReturnsAsExpected()
        {
            // Setup
            var fixture = new Ploeh.AutoFixture.Fixture ().Customize ( new AutoMoqCustomization () );
            var parentPropertyName = fixture.CreateAnonymous<string> ();
            var childPropertyName = fixture.CreateAnonymous<string> ();
            var propertyChainList = new List<string> { parentPropertyName, childPropertyName };
            var sut = new PropertyChain ( propertyChainList );

            // Exercise
            var str = sut.ToString ();

            // Verify
            Assert.AreEqual(parentPropertyName+"."+childPropertyName, str);
        }
示例#7
0
        public void ToString_GivenPropertyChain_ReturnsAsExpected()
        {
            // Setup
            var fixture            = new Ploeh.AutoFixture.Fixture().Customize(new AutoMoqCustomization());
            var parentPropertyName = fixture.CreateAnonymous <string> ();
            var childPropertyName  = fixture.CreateAnonymous <string> ();
            var propertyChainList  = new List <string> {
                parentPropertyName, childPropertyName
            };
            var sut = new PropertyChain(propertyChainList);

            // Exercise
            var str = sut.ToString();

            // Verify
            Assert.AreEqual(parentPropertyName + "." + childPropertyName, str);
        }
        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);
        }