예제 #1
0
        public ActionResult Create()
        {
            var model = new AcquisitionModel
              {
            Date = DateTime.Today.ToString(Constants.DATE_FORMAT),
            Items = new List<AcquisitionItemModel> { new AcquisitionItemModel() }
              };

              return View(model);
        }
예제 #2
0
            public void UpdatesTheStock()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc"});
                products.Add(new Product {Id = 2, Name = "def", SalePrice = 12.34m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Name = "abc", Quantity = 22.35m});

                var model = new AcquisitionModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new AcquisitionItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new AcquisitionItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddAcquisition(model);

                stocks.Should().HaveCount(2);
                stocks[0].Quantity.Should().Be(23.58m);
                var addedStock = stocks[1];
                addedStock.ShouldBeEquivalentTo(new Stock
                {
                  Id = 2,
                  ProductId = 2,
                  Name = "def",
                  SalePrice = 12.34m,
                  Quantity = 5.67m,
                  PurchaseValue = 45.36m,
                  SaleValue = 69.97m,
                });
            }
예제 #3
0
            public void IgnoresItemsWithInvalidFields()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 4, Name = "d"});
                var model = new AcquisitionModel
                {
                  CompanyName = "Microsoft",
                  Date = "1/1/2000",
                  Items = new[]
                  {
                new AcquisitionItemModel {ProductName = null, Quantity = "1", Price = "1"},
                new AcquisitionItemModel {ProductName = "b", Quantity = "", Price = "2"},
                new AcquisitionItemModel {ProductName = "c", Quantity = "3", Price = ""},
                new AcquisitionItemModel {ProductName = "d", Quantity = "4", Price = "4"},
                  },
                };

                sut.AddAcquisition(model);

                acquisitions.Should().HaveCount(1);
                var acquisition = acquisitions[0];
                acquisition.ShouldBeEquivalentTo(new Acquisition
                {
                  Id = 1,
                  Company = new Company {Id = 1, Name = "Microsoft"},
                  Date = new DateTime(2000, 1, 1),
                  Items = new Collection<AcquisitionItem>
                  {
                new AcquisitionItem
                {
                  Product = new Product {Id = 4, Name = "d"},
                  ProductId = 4,
                  Quantity = 4.00m,
                  Price = 4.00m,
                },
                  }
                });
            }
예제 #4
0
            public void DoesNotAddTheRootObjectIfAllItemsAreInvalid()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                var model = new AcquisitionModel
                {
                  CompanyName = "Microsoft",
                  Date = "1/1/2000",
                  Items = new[]
                  {
                new AcquisitionItemModel {ProductName = null, Quantity = "1", Price = "1"},
                new AcquisitionItemModel {ProductName = "b", Quantity = "", Price = "2"},
                new AcquisitionItemModel {ProductName = "c", Quantity = "3", Price = ""},
                  },
                };

                sut.AddAcquisition(model);

                acquisitions.Should().BeEmpty();
            }
예제 #5
0
            public void CommitsTheTransaction()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc"});
                products.Add(new Product {Id = 2, Name = "def", SalePrice = 12.34m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Name = "abc", Quantity = 22.35m});

                var model = new AcquisitionModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new AcquisitionItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new AcquisitionItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddAcquisition(model);

                transaction.Verify(it => it.Commit());
            }
예제 #6
0
            public void AddsTheMissingProducts()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 12.34m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});

                var model = new AcquisitionModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new AcquisitionItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new AcquisitionItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddAcquisition(model);

                products.Should().HaveCount(2);
                products[0].Name.Should().Be("abc");
                products[1].Name.Should().Be("def");
            }
예제 #7
0
            public void AddsTheCorrectValuesToTheRepository()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc"});
                products.Add(new Product {Id = 2, Name = "def"});
                var model = new AcquisitionModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new AcquisitionItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new AcquisitionItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddAcquisition(model);

                acquisitions.Should().HaveCount(1);
                var acquisition = acquisitions[0];
                acquisition.ShouldBeEquivalentTo(new Acquisition
                {
                  Id = 1,
                  Company = new Company {Id = 1, Name = "Microsoft"},
                  Date = new DateTime(2000, 2, 3),
                  Items = new Collection<AcquisitionItem>
                  {
                new AcquisitionItem
                {
                  Product = new Product {Id = 1, Name = "abc"},
                  ProductId = 1,
                  Quantity = 1.23m,
                  Price = 4.00m,
                },
                new AcquisitionItem
                {
                  Product = new Product {Id = 2, Name = "def"},
                  ProductId = 2,
                  Quantity = 5.67m,
                  Price = 8.00m,
                }
                  }
                });
                repository.Verify(it => it.SaveChanges());
            }
예제 #8
0
            public void AddsTheCompanyIfNeeded()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                var model = new AcquisitionModel
                {
                  CompanyName = "Google",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new AcquisitionItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new AcquisitionItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddAcquisition(model);

                companies.Should().HaveCount(2);
                companies[1].Name.Should().Be("Google");
            }
예제 #9
0
        public ActionResult Create(AcquisitionModel model)
        {
            logic.AddAcquisition(model);

              return RedirectToAction("Create");
        }