Beispiel #1
0
        public async Task ShouldRetornarTodosSupplieres()
        {
            var supplierA = new SupplierBuilder()
                            .Withcpnj("85.224.941/0001-61")
                            .WithEmail(new Email("*****@*****.**"))
                            .WithAdress(new Address("Rua amazonas", "bairro joaonese", "marilandia", "SC", 102))
                            .WithTradingName("Great bar")
                            .WithCorporateName("Joaozeti")
                            .WithTelephone(new Telephone("(47)99620-7702"))
                            .Construct();

            var supplierB = new SupplierBuilder()
                            .Withcpnj("85.224.941/0001-61")
                            .WithEmail(new Email("*****@*****.**"))
                            .WithAdress(new Address("Rua amazonas", "bairro joase", "joanópolis", "SC", 102))
                            .WithTradingName("Great abar")
                            .WithCorporateName("Joazaainho carlos ltda")
                            .WithTelephone(new Telephone("(47)99720-7702"))
                            .Construct();

            var supplieres = new List <Supplier>();

            supplieres.Add(supplierA);
            supplieres.Add(supplierB);

            _supplierRepository.GetAll().Returns(supplieres);

            var supplieresRetornados = await _supplierService.GetAll();

            supplieresRetornados.Should().HaveCount(2);
            supplieresRetornados[0].TradingName.Should().Be(supplierA.TradingName);
            supplieresRetornados[0].cpnj.Should().Be(supplierA.cpnj);
            supplieresRetornados[1].TradingName.Should().Be(supplierB.TradingName);
        }
Beispiel #2
0
        public async Task ShouldUpdateSupplier()
        {
            var supplierId = Guid.NewGuid();
            var model      = new SupplierRequestModel()
            {
                cpnj          = "85.224.941/0001-61",
                TradingName   = "Great bar",
                Email         = "*****@*****.**",
                Address       = new Address("Rua amazonas", "bairro joaonese", "marilandia", "SC", 102),
                CorporateName = "Joazinho carlos ltda",
                Telephone     = "(47)99620-7702"
            };
            var supplier = new SupplierBuilder()
                           .Withcpnj("85.224.941/0001-61")
                           .WithEmail(new Email("*****@*****.**"))
                           .WithAdress(new Address("Rua amazonas", "bairro joaonese", "marilandia", "SC", 102))
                           .WithTradingName("Joao joazito")
                           .WithCorporateName("Joazinho carlos ltda")
                           .WithTelephone(new Telephone("(47)99620-7702"))
                           .Construct();

            _supplierRepository
            .GetById(supplierId)
            .Returns(supplier);

            await _supplierService
            .Update(supplierId, model);

            await _supplierRepository
            .Received(1)
            .Update(Arg.Is <Supplier>(x => x.TradingName == "Great bar"));
        }
        public void get_cheapest_supplier_for_product()
        {
            var product = new ProductBuilder().Build();
            var supplier1 = new SupplierBuilder().Build();
            var supplier2 = new SupplierBuilder().Build();
            var supplier3 = new SupplierBuilder().Build();
            product.AddSource(supplier1, 50);
            product.AddSource(supplier2, 48);
            product.AddSource(supplier3, 52);
            Session.Save(product);
            Session.Flush();

            var cheapestSupplier =
                Session.CreateQuery(
                    "select ps.Supplier from ProductSource ps where ps.Product.Id = :productId order by ps.Cost asc")
                    .SetParameter("productId", product.Id)
                    .SetMaxResults(1)
                    .UniqueResult<Supplier>();

            // the following LINQ approach also works, but uses an uneccessary join on Supplier in the subselect!
            //var cheapestSupplierId = Session.Query<ProductSource>()
            //    .Where(s => s.Product.Id == product.Id)
            //    .OrderBy(s => s.Cost)
            //    .Select(s => s.Supplier.Id)
            //    .Take(1);

            //var cheapestSupplier = Session.Query<Supplier>()
            //    .Where(s => s.Id == cheapestSupplierId.Single())
            //    .Single();

            Assert.AreEqual(supplier2, cheapestSupplier);
        }
Beispiel #4
0
        public void get_cheapest_supplier_for_product()
        {
            var product   = new ProductBuilder().Build();
            var supplier1 = new SupplierBuilder().Build();
            var supplier2 = new SupplierBuilder().Build();
            var supplier3 = new SupplierBuilder().Build();

            product.AddSource(supplier1, 50);
            product.AddSource(supplier2, 48);
            product.AddSource(supplier3, 52);
            Session.Save(product);
            Session.Flush();

            var cheapestSupplier =
                Session.CreateQuery(
                    "select ps.Supplier from ProductSource ps where ps.Product.Id = :productId order by ps.Cost asc")
                .SetParameter("productId", product.Id)
                .SetMaxResults(1)
                .UniqueResult <Supplier>();

            // the following LINQ approach also works, but uses an uneccessary join on Supplier in the subselect!
            //var cheapestSupplierId = Session.Query<ProductSource>()
            //    .Where(s => s.Product.Id == product.Id)
            //    .OrderBy(s => s.Cost)
            //    .Select(s => s.Supplier.Id)
            //    .Take(1);

            //var cheapestSupplier = Session.Query<Supplier>()
            //    .Where(s => s.Id == cheapestSupplierId.Single())
            //    .Single();

            Assert.AreEqual(supplier2, cheapestSupplier);
        }
Beispiel #5
0
            public void Always_AssignsValues()
            {
                var supplier      = new SupplierBuilder().Build();
                var purchaseOrder = new PurchaseOrder(new OrderNo("orderNo"), supplier);

                Assert.That(purchaseOrder.OrderNo.Value, Is.EqualTo("orderNo"));
                Assert.That(purchaseOrder.Supplier, Is.SameAs(supplier));
            }
Beispiel #6
0
        private static IEnumerable <Supplier> FakeSuppliers()
        {
            var supplier = new SupplierBuilder()
                           .WithCompanyName(TestCompanyName)
                           .Build();

            return(new List <Supplier> {
                supplier
            });
        }
Beispiel #7
0
 public static List <Supplier> aListOfSuppliers()
 => new List <Supplier>
 {
     SupplierBuilder.aSupplierBuilder().WithName("Asus").ToRepository(),
     SupplierBuilder.aSupplierBuilder().WithName("Razer").ToRepository(),
     SupplierBuilder.aSupplierBuilder().WithName("Samsung").ToRepository(),
     SupplierBuilder.aSupplierBuilder().WithName("MSI").ToRepository(),
     SupplierBuilder.aSupplierBuilder().WithName("NZXT").ToRepository(),
     SupplierBuilder.aSupplierBuilder().WithName("Corsair").ToRepository(),
     SupplierBuilder.aSupplierBuilder().WithName("WesternDigital").ToRepository(),
 };
Beispiel #8
0
            public void ProductIsFromSameSupplier_LineItemAddedToCollection()
            {
                var supplier      = new SupplierBuilder().Id(123).Build();
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(supplier)
                                    .Build();
                var lineItem = new PurchaseOrderLineBuilder()
                               .Product(new ProductBuilder().SupplierId(123).Build())
                               .Build();

                purchaseOrder.AddLineItem(lineItem);
            }
Beispiel #9
0
            public void ProductIsFromDifferentSupplier_ExceptionThrown()
            {
                var supplier      = new SupplierBuilder().Id(123).Build();
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(supplier)
                                    .Build();
                var lineItem = new PurchaseOrderLineBuilder()
                               .Product(new ProductBuilder().SupplierId(789).Build())
                               .Build();

                Assert.Throws <PurchaseOrderTrackerException>(() => purchaseOrder.AddLineItem(lineItem));
            }
Beispiel #10
0
            public void PurchaseOrderIsNotOpen_ExceptionThrown()
            {
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(new SupplierBuilder().Id(111).Build())
                                    .Build();
                var newSupplier = new SupplierBuilder().Id(222).Build();

                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Approved);
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Shipped);
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Delivered);

                Assert.Throws <PurchaseOrderTrackerException>(() => purchaseOrder.ChangeSupplier(newSupplier));
            }
        public IActionResult About(int id)
        {
            SupplierBuilder  supplier = new SupplierBuilder();
            FranchiseBuilder company  = new FranchiseBuilder();

            List <Franchise> allStores = company.SellFranchise();

            ProductOrderingViewModel viewModel = new ProductOrderingViewModel();

            viewModel.Store     = allStores.SingleOrDefault(store => store.Id == id);
            viewModel.Suppliers = supplier.GetSuppliers();

            return(View(viewModel));
        }
        public IActionResult Index()
        {
            FranchiseBuilder company      = new FranchiseBuilder();
            SupplierBuilder  allSuppliers = new SupplierBuilder();

            List <Franchise> allStores = company.SellFranchise();


            StoreListViewModel viewModel = new StoreListViewModel();

            viewModel.Stores    = allStores;
            viewModel.Suppliers = allSuppliers.GetSuppliers();

            return(View(viewModel));
        }
        public void get_cheapest_supplier_for_product()
        {
            var product = new ProductBuilder().Build();
            var supplier1 = new SupplierBuilder().Build();
            var supplier2 = new SupplierBuilder().Build();
            var supplier3 = new SupplierBuilder().Build();
            product.AddSource(supplier1, 50);
            product.AddSource(supplier2, 48);
            product.AddSource(supplier3, 52);
            Session.Save(product);
            Session.Flush();

            Supplier cheapestSupplier = null;

            Assert.AreEqual(supplier2, cheapestSupplier);
        }
        public void get_cheapest_supplier_for_product()
        {
            var product   = new ProductBuilder().Build();
            var supplier1 = new SupplierBuilder().Build();
            var supplier2 = new SupplierBuilder().Build();
            var supplier3 = new SupplierBuilder().Build();

            product.AddSource(supplier1, 50);
            product.AddSource(supplier2, 48);
            product.AddSource(supplier3, 52);
            Session.Save(product);
            Session.Flush();

            Supplier cheapestSupplier = null;

            Assert.AreEqual(supplier2, cheapestSupplier);
        }
Beispiel #15
0
            public void PurchaseOrderIsOpen_SupplierChangedAndLineItemsCleared()
            {
                var product       = new ProductBuilder().SupplierId(111).Build();
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(new SupplierBuilder().Id(111).Build())
                                    .LineItems(
                    new List <PurchaseOrderLine>
                {
                    new PurchaseOrderLineBuilder().Product(product).Build(),
                    new PurchaseOrderLineBuilder().Product(product).Build(),
                    new PurchaseOrderLineBuilder().Product(product).Build()
                })
                                    .Build();
                var newSupplier = new SupplierBuilder().Id(222).Build();

                purchaseOrder.ChangeSupplier(newSupplier);

                Assert.That(purchaseOrder.LineItems.Any(), Is.False);
                Assert.That(purchaseOrder.Supplier, Is.SameAs(newSupplier));
            }
Beispiel #16
0
        public async Task ShouldGetSupplierPorId()
        {
            var userId = Guid.NewGuid();
            var user   = new SupplierBuilder()
                         .Withcpnj("85.224.941/0001-61")
                         .WithEmail(new Email("*****@*****.**"))
                         .WithAdress(new Address("Rua amazonas", "bairro joaonese", "marilandia", "SC", 102))
                         .WithTradingName("Great bar")
                         .WithCorporateName("Joazinho carlos ltda")
                         .WithTelephone(new Telephone("(47)99620-7702"))
                         .Construct();

            _supplierRepository
            .GetById(userId)
            .Returns(user);

            var supplierRetornado = await _supplierService
                                    .GetById(userId);

            supplierRetornado.TradingName.Should().Be("Great bar");
        }
Beispiel #17
0
        public void should_update_supplier()
        {
            var supplierId = Guid.NewGuid();
            var supplier   = new SupplierBuilder()
                             .Withcpnj("85.224.941/0001-61")
                             .WithEmail(new Email("*****@*****.**"))
                             .WithId(supplierId)
                             .WithCorporateName("Joao ltda")
                             .WithTradingName("Bar do joao")
                             .WithTelephone(new Telephone("(47)99620-7702"))
                             .WithAdress(new Address("Rua amazonas", "bairro joaonese", "marilandia", "SC", 102))
                             .Construct();

            supplier.Update("joaozinho ltda", "11.444.443/0001-98", "bar do joaozinho", "*****@*****.**",
                            "(47)99620-7702", new Address("Rua amazonas", "bairro carlos silva", "cascalho", "SC", 107));

            supplier.Email.ToString().Should().Be("*****@*****.**");
            supplier.TradingName.Should().Be("bar do joaozinho");
            supplier.CorporateName.Should().Be("joaozinho ltda");
            supplier.Address.Should().Equals(new Address("Rua amazonas", "bairro carlos silva", "cascalho", "SC", 107));
            supplier.cpnj.Should().Be("11.444.443/0001-98");
        }
Beispiel #18
0
 public static SupplierBuilder aDefaultSupplier()
 => SupplierBuilder.aSupplierBuilder();