Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            this.supplies = LoadSupplies();

            this.DataContext = new ViewModels.MainViewModel(this.supplies);
            ((ViewModels.MainViewModel) this.DataContext).SuppliesChanged += (s, e) => this.SaveSupplies();
        }
Ejemplo n.º 2
0
        public void RemainingStockShouldBeBasedOnDosageAndRefill()
        {
            // arrange
            var supplies = new Supplies();
            supplies.AddDosage(VitaminumC, new DateTime(2014, 1, 1), FivePerDay);

            supplies.Refill(VitaminumC, new Stock(100, new DateTime(2014, 1, 1)));

            // act
            var remaining = supplies.RemainingStock(VitaminumC, new DateTime(2014, 1, 5));

            // assert
            Assert.That(remaining, Is.EqualTo(new Stock(80, new DateTime(2014, 1, 5))));
        }
Ejemplo n.º 3
0
        public void ExhaustionDateShouldBeBasedOnDosageAndRefill()
        {
            // arrange
            var supplies = new Supplies();
            supplies.AddDosage(VitaminumC,  new DateTime(2014, 1, 1), FivePerDay);

            supplies.Refill(VitaminumC, new Stock(100, new DateTime(2014, 1, 1)));

            // act
            var exhaustionDate = supplies.ExhaustionOf(VitaminumC);

            // assert
            Assert.That(exhaustionDate, Is.EqualTo(new DateTime(2014, 1, 20)));
        }
Ejemplo n.º 4
0
        public void MultipleRefillShouldUpdateStockInProperWay()
        {
            // arrange
            var supplies = new Supplies();
            supplies.AddDosage(VitaminumC, new DateTime(2014, 1, 1), FivePerDay);

            supplies.Refill(VitaminumC, new Stock(100, new DateTime(2014, 1, 1)));
            supplies.Refill(VitaminumC, new Stock(50, new DateTime(2014, 1, 5)));

            // act
            var stock = supplies.CurrentStock(VitaminumC);

            // assert
            Assert.That(stock, Is.EqualTo(new Stock(130, new DateTime(2014, 1, 5))));
        }
Ejemplo n.º 5
0
        public MainViewModel(Supplies supplies)
        {
            this.supplies = supplies;

            this.asOfDate = DateTime.Today;

            this.AddMedicineCommand = new DelegateCommand(AddMedicine);
            this.RefillCommand = new DelegateCommand<string>(RefillMedicine);
            this.ChangeDosageCommand = new DelegateCommand<string>(ChangeDosage);
            this.RefillAllCommand = new DelegateCommand(RefillAllMedicine);
            this.ExcelReportCommand = new DelegateCommand(ExcelReport);
            this.RemoveMedicineCommand = new DelegateCommand<string>(RemoveMedicine);
            this.PrintCommand = new DelegateCommand(Print);

            this.Medicines = new ObservableCollection<MedicineStatus>();

            this.DumpSuppliesStatus();
        }
Ejemplo n.º 6
0
        public void SaveTest()
        {
            // arrange
            var supplies = new Supplies();
            supplies.AddDosage(new Medicine("VitaminumC"), DateTime.Today.AddDays(-7), new CountPerDayDosage(5));
            supplies.Refill(new Medicine("VitaminumC"), new Stock(100, DateTime.Today.AddDays(-7)));
            supplies.AddDosage(new Medicine("VitaminumD"), DateTime.Today.AddDays(-7), new CountPerDayDosage(5));
            supplies.Refill(new Medicine("VitaminumD"), new Stock(100, DateTime.Today.AddDays(-7)));
            supplies.AddDosage(new Medicine("VitaminumE"), DateTime.Today.AddDays(-7), new CountPerDayDosage(5));
            supplies.Refill(new Medicine("VitaminumE"), new Stock(100, DateTime.Today.AddDays(-7)));

            var repo = new Repository();

            // act
            var json = repo.DumpJson(supplies);
            var readed = repo.ReadJson(json);
            var jsonForRestored = repo.DumpJson(readed);

            // assert
            Console.WriteLine(jsonForRestored);
            Assert.That(json, Is.EqualTo(jsonForRestored));
        }
Ejemplo n.º 7
0
        public void Bug_MixedValuesInJson()
        {
            // arrange
            var dx = new Medicine("DX");
            var p = new Medicine("P");
            var d5 = new Medicine("D5");
            var d3 = new Medicine("D3");

            var original = new Supplies();

            original.AddDosage(dx, new DateTime(2013, 12, 21), new CountPerDayDosage(3));
            original.AddDosage(p, new DateTime(2013, 12, 21), new CountPerDayDosage(1));
            original.AddDosage(d5, new DateTime(2013, 12, 21), new CountPerDayDosage(2));
            original.AddDosage(d3, new DateTime(2013, 11, 27), new CountPerDayDosage(1));

            original.Refill(new Dictionary<Medicine, Stock>
            {
                {dx, new Stock(205, new DateTime(2013, 12, 21))},
                {p, new Stock(60, new DateTime(2013, 12, 21))},
                {d5, new Stock(181, new DateTime(2013, 12, 21))},
                {d3, new Stock(100, new DateTime(2013, 11, 27))},
            });

            var repo = new Repository();

            // act
            var json = repo.DumpJson(original);
            var restored = repo.ReadJson(json);

            // assert
            Console.WriteLine(json);
            foreach (var medicine in original.GetMedicines())
            {
                Assert.That(restored.CurrentStock(medicine), Is.EqualTo(original.CurrentStock(medicine)), "CurrentStock: " + medicine.Name);
                Assert.That(restored.ExhaustionOf(medicine), Is.EqualTo(original.ExhaustionOf(medicine)), "ExhaustionDate: " + medicine.Name);
                Assert.That(restored.RemainingStock(medicine, DateTime.Today), Is.EqualTo(original.RemainingStock(medicine, DateTime.Today)), "RemainingStock: " + medicine.Name);
            }
        }
Ejemplo n.º 8
0
 public string DumpJson(Supplies supplies)
 {
     return JsonConvert.SerializeObject(supplies, SerializerSettings);
 }