コード例 #1
0
        public IActionResult Upload(IFormFile xmlFile)
        {
            var result = uploadSoldMedicines.Execute(xmlFile);

            return(result.Succes ?
                   RedirectToAction(nameof(Succes), result) :
                   RedirectToAction(nameof(Failed), result));
        }
コード例 #2
0
        public void Should_Not_Add_Medicines_To_Sold_And_Substract_From_External_Drugstore()
        {
            // given
            var expectedSoldAmount = context.ExternalDrugstoreSoldMedicines.Sum(ex => ex.SoldQuantity);
            var fileFormMock       = new Mock <IFormFile>();

            fileFormMock.Setup(f => f.ContentType).Returns("text/xml");
            var fileCopyMock   = new Mock <ICopy>();
            var loggerMock     = new Mock <ILogger <UploadSoldMedicinesListUseCase> >();
            var serializerMock = new Mock <ISerializer <MemoryStream, XmlMedicineSupplyModel> >();

            serializerMock.Setup(s => s.Deserialize(It.IsAny <MemoryStream>())).Returns(supply);

            var useCase = new UploadSoldMedicinesListUseCase(
                context,
                loggerMock.Object,
                serializerMock.Object,
                fileCopyMock.Object);

            supply.Medicines.First().Quantity = 100;
            context.SaveChanges();

            // when
            var result = useCase.Execute(fileFormMock.Object);

            // then
            int expectedAdditionalSoldMeds = 0;
            var expectedQuantity           = initialQuantity;

            supply.Medicines.ForEach(m =>
            {
                expectedAdditionalSoldMeds += (int)m.Quantity;

                var actualQuantity = context.ExternalDrugstoreMedicines
                                     .First(ex => ex.StockMedicine.ID == m.StockId).Quantity;
                Assert.AreEqual(expectedQuantity, actualQuantity);
            });

            int actualAmount = context.ExternalDrugstoreSoldMedicines.Sum(ex => ex.SoldQuantity);

            Assert.AreEqual(expectedSoldAmount, actualAmount);
        }