Example #1
0
 public void CannotSetEmptyPrice()
 {
     Assert.Catch(() =>
     {
         var x = new DairyProduct("Milk", null, new Measurement(1, Unit.LITER), new DateTime(2018, 04, 03));
     });
 }
Example #2
0
        public void CannotSetEmptyLabel()
        {
            Assert.Catch(() =>
            {
                var x = new DairyProduct("", new Price(1.20m, Currency.EUR), new Measurement(1, Unit.LITER), new DateTime(2018, 04, 03));
            });

            Assert.Catch(() =>
            {
                var x = new DairyProduct(null, new Price(1.20m, Currency.EUR), new Measurement(1, Unit.LITER), new DateTime(2018, 04, 03));
            });
        }
Example #3
0
        public void CanCreateDairyProduct()
        {
            var x = new DairyProduct("Milk", new Price(1.20m, Currency.EUR), new Measurement(1, Unit.LITER), new DateTime(2018, 04, 03));

            Assert.IsTrue(x.Label.Equals("Milk"));
            Assert.IsTrue(x.Price.Amount.Equals(1.20m));
            Assert.IsTrue(x.Price.Currency.Equals(Currency.EUR));
            Assert.IsTrue(x.Measurement.Amount.Equals(1));
            Assert.IsTrue(x.Measurement.Unit.Equals(Unit.LITER));
            Assert.IsTrue(x.ExpirationDate.Year.Equals(2018));
            Assert.IsTrue(x.ExpirationDate.Month.Equals(04));
            Assert.IsTrue(x.ExpirationDate.Day.Equals(03));
        }
Example #4
0
        protected override void Seed(AgriIPCAContext context)
        {
            User defaultUser  = new User("user", "user", Role.User);
            User defaultAdmin = new User("admin", "admin", Role.Admin);

            context.Users.Add(defaultUser);
            context.Users.Add(defaultAdmin);
            context.SaveChanges();

            Animal horse = new Animal("Long horse", 2000, 2, "horse");

            context.Products.Add(horse);

            Cereals wheat = new Cereals("Crunchy", 0.22m, 1000);

            context.Products.Add(wheat);

            Meat meat = new Meat("Pork Meat", 5.89m, 100, new DateTime(2018, 5, 27));

            context.Products.Add(meat);

            DairyProduct milk = new DairyProduct("Mr. Milk", 0.7m, 1000, new DateTime(2018, 3, 28));

            context.Products.Add(milk);

            DairyProduct cheese = new DairyProduct("Alpy", 7, 30, new DateTime(2018, 7, 12));

            context.Products.Add(cheese);

            context.SaveChanges();

            Purchase p1 = new Purchase(cheese.Id, defaultUser.Id, DateTime.Now, 10, 7.23m);
            Purchase p2 = new Purchase(milk.Id, defaultUser.Id, DateTime.Now, 100, 0.43m);
            Purchase p3 = new Purchase(wheat.Id, defaultUser.Id, new DateTime(2018, 5, 10), 10, 0.27m);
            Purchase p4 = new Purchase(cheese.Id, defaultUser.Id, new DateTime(2018, 4, 8), 2, 6.99m);
            Purchase p5 = new Purchase(meat.Id, defaultUser.Id, new DateTime(2018, 6, 1), 10, 6.58m);

            context.Purchases.Add(p1);
            context.Purchases.Add(p2);
            context.Purchases.Add(p3);
            context.Purchases.Add(p4);
            context.Purchases.Add(p5);
            context.SaveChanges();
        }
Example #5
0
        public void TestExpiryCheck()
        {
            DateTime today, yesterday, tomorrow;

            today     = DateTime.Today;
            yesterday = DateTime.Today.AddDays(-1);
            tomorrow  = DateTime.Today.AddDays(1);

            var x = new DairyProduct("Milk", new Price(1.20m, Currency.EUR), new Measurement(1, Unit.LITER), today);

            Assert.IsTrue(x.HasExpired() == false);


            x = new DairyProduct("Milk", new Price(1.20m, Currency.EUR), new Measurement(1, Unit.LITER), yesterday);
            Assert.IsTrue(x.HasExpired() == true);


            x = new DairyProduct("Milk", new Price(1.20m, Currency.EUR), new Measurement(1, Unit.LITER), tomorrow);
            Assert.IsTrue(x.HasExpired() == false);
        }
Example #6
0
        private string CreateDairyProduct()
        {
            this.writer.Write("Name: ");
            string name = this.reader.Read();

            this.writer.Write("Price: ");
            decimal price = decimal.Parse(this.reader.Read());

            this.writer.Write("Quantity: ");
            int quantity = int.Parse(this.reader.Read());

            this.writer.Write("Best Before(inserted date should be in format 'dd/mm/yyyy'): ");
            DateTime bestBefore = DateTime.ParseExact(this.reader.Read(), "dd/mm/yyyy", CultureInfo.InvariantCulture);

            DairyProduct dairy = new DairyProduct(name, price, quantity, bestBefore);

            this.context.Products.Add(dairy);
            this.context.SaveChanges();

            return("The dairy product has been successfully added to the database");
        }