コード例 #1
0
        public async Task TestAddProduct()
        {
            var piId            = new ProductInfo();
            var expectedProduct = new Product
            {
                Amount        = 200,
                Id            = new ObjectId(),
                Price         = 10,
                ProductInfoId = piId.Id,
                PZN           = 01,
                Unit          = DBI_Apotheke.Core.Workloads.Modules.Unit.G
            };
            var repoMock = Substitute.For <IProductRepository>();

            repoMock.InsertItem(Arg.Any <Product>()).Returns(c =>
            {
                var p = c.ArgAt <Product>(0);
                p.Id  = expectedProduct.Id;
                return(p);
            });
            var repoMockPI = Substitute.For <IProductInfoRepository>();

            repoMockPI.GetItemById(expectedProduct.ProductInfoId).Returns(new ProductInfo {
            });

            var service   = new ProductService(Substitute.For <IDateTimeProvider>(), repoMock);
            var servicePi = new ProductInfoService(Substitute.For <IDateTimeProvider>(), repoMockPI);

            var resPi = await servicePi.GetItemById(expectedProduct.ProductInfoId);

            var actualProduct = await service.InsertItem(resPi,
                                                         expectedProduct.PZN,
                                                         expectedProduct.Price,
                                                         expectedProduct.Amount,
                                                         expectedProduct.Unit);

            await repoMock.Received(1).InsertItem(Arg.Any <Product>());

            actualProduct.Should().NotBeNull();
            actualProduct.Should().BeEquivalentTo(expectedProduct);
        }
コード例 #2
0
        public async Task TestGetProductInfoById()
        {
            var idPI       = new ObjectId();
            var ingredient = new Ingredient
            {
                Amount = 100,
                Name   = "Wirkstoff A",
                Unit   = DBI_Apotheke.Core.Workloads.Modules.Unit.G
            };
            var list = new List <Ingredient>();

            list.Add(ingredient);
            var repoMock = Substitute.For <IProductInfoRepository>();

            repoMock.GetItemById(Arg.Any <ObjectId>()).Returns(ci => new ProductInfo
            {
                Id          = ci.Arg <ObjectId>(),
                Brand       = "Aspirin",
                Ingredients = list,
                Name        = "AspirinComplex"
            });
            var expected = new ProductInfo
            {
                Brand       = "Aspirin",
                Id          = idPI,
                Ingredients = list,
                Name        = "AspirinComplex"
            };

            var service     = new ProductInfoService(Substitute.For <IDateTimeProvider>(), repoMock);
            var productInfo = await service.GetItemById(idPI);

            await repoMock.Received(1).GetItemById(Arg.Is(idPI));

            productInfo.Should().NotBeNull();
            productInfo !.Id.Should().Be(expected.Id);
            productInfo !.Ingredients.Should().BeEquivalentTo(expected.Ingredients);
            productInfo !.Name.Should().Be(expected.Name);
            productInfo !.Brand.Should().Be(expected.Brand);
        }