Exemplo n.º 1
0
        public void AddNewOrderWithoutCustomerIdThrowArgumentException()
        {
            //Arrange

            var customerRepository = new Mock <ICustomerRepository>();
            var productRepository  = new Mock <IProductRepository>();
            var orderRepository    = new Mock <IOrderRepository>();
            Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >();

            var salesManagement = new SalesAppService(productRepository.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object);

            var order = new OrderDTO() // order is not valid when customer id is empty
            {
                CustomerId = Guid.Empty
            };

            Exception ex = Assert.Throws <ArgumentException>(() =>
            {
                //act
                var result = salesManagement.AddNewOrder(order);

                //assert
                Assert.Null(result);
            }
                                                             );

            Assert.IsType(typeof(ArgumentException), ex);
        }
Exemplo n.º 2
0
        public void AddNewValidOrderReturnAddedOrder()
        {
            //Arrange

            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();
            var customerRepository = new SICustomerRepository();
            var country            = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "+34343", "company", country, new Address("city", "zipCode", "addressline1", "addressline2"));

                return(customer);
            };


            orderRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };
            orderRepository.AddOrder = (order) => { };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new OrderDTO()
            {
                CustomerId      = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity    = "city",
                ShippingName    = "name",
                ShippingZipCode = "zipcode",
                OrderLines      = new List <OrderLineDTO>()
                {
                    new OrderLineDTO()
                    {
                        ProductId = Guid.NewGuid(), Amount = 1, Discount = 0, UnitPrice = 20
                    }
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.ShippingAddress, dto.ShippingAddress);
            Assert.AreEqual(result.ShippingCity, dto.ShippingCity);
            Assert.AreEqual(result.ShippingName, dto.ShippingName);
            Assert.AreEqual(result.ShippingZipCode, dto.ShippingZipCode);
            Assert.IsTrue(result.OrderLines.Count == 1);
            Assert.IsTrue(result.OrderLines.All(ol => ol.Id != Guid.Empty));
        }
        public void AddNewOrderWithTotalGreaterCustomerCreditReturnNull()
        {
            //Arrange
            var productRepository  = new StubIProductRepository();
            var orderRepository    = new StubIOrderRepository();
            var customerRepository = new StubICustomerRepository();
            var country            = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer(
                    "Jhon",
                    "El rojo",
                    "+34343",
                    "company",
                    country,
                    new Address("city", "zipCode", "addressline1", "addressline2"));

                return(customer);
            };

            orderRepository.UnitOfWorkGet = () =>
            {
                var uow = new StubIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };
            orderRepository.AddOrder = (order) => { };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new OrderDto()
            {
                CustomerId      = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity    = "city",
                ShippingName    = "name",
                ShippingZipCode = "zipcode",
                OrderLines      = new List <OrderLineDto>()
                {
                    new OrderLineDto()
                    {
                        ProductId = Guid.NewGuid(),
                        Amount    = 1,
                        Discount  = 0,
                        UnitPrice = 2000
                    }
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.IsNull(result);
        }
Exemplo n.º 4
0
        public void AddNewOrderWithTotalGreaterCustomerCreditReturnNull()
        {
            //Arrange
            var productRepository  = new Mock <IProductRepository>();
            var orderRepository    = new Mock <IOrderRepository>();
            var customerRepository = new Mock <ICustomerRepository>();
            var country            = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository
            .Setup(x => x.Get(It.IsAny <Guid>()))
            .Returns((Guid guid) => {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "+34343", "company", country, new Address("city", "zipCode", "addressline1", "addressline2"));

                return(customer);
            });

            Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>();

            _mockContext.Setup(c => c.Commit());

            orderRepository.Setup(x => x.Add(It.IsAny <Order>()));

            orderRepository
            .Setup(x => x.UnitOfWork).Returns(_mockContext.Object);

            Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >();

            var salesManagement = new SalesAppService(productRepository.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object);

            var dto = new OrderDTO()
            {
                CustomerId      = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity    = "city",
                ShippingName    = "name",
                ShippingZipCode = "zipcode",
                OrderLines      = new List <OrderLineDTO>()
                {
                    new OrderLineDTO()
                    {
                        ProductId = Guid.NewGuid(), Amount = 1, Discount = 0, UnitPrice = 2000
                    }
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.Null(result);
        }
Exemplo n.º 5
0
        public void AddNewOrderWithoutCustomerIdThrowArgumentException()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var order = new OrderDTO() // order is not valid when customer id is empty
            {
                CustomerId = Guid.Empty
            };

            //act
            var result = salesManagement.AddNewOrder(order);

            //assert
            Assert.IsNull(result);
        }