public void DuplicateBarcodesAreNotSaved()
        {
            // Setup
            ImportCompanyProductBarcodeCsvService.Setup(m => m.GetRecords(It.IsAny <Stream>(), It.IsAny <ClassMap <ImportCompanyProductBarcodeDto> >()))
            .Returns(new List <ImportCompanyProductBarcodeDto>()
            {
                new ImportCompanyProductBarcodeDto
                {
                    SupplierCode = TestData.SupplierCode,
                    ProductSku   = TestData.ProductSkuCompanyCodeA,
                    Barcode      = TestData.BarcodeProductSkuCompanyCodeA
                },
                new ImportCompanyProductBarcodeDto
                {
                    SupplierCode = TestData.SupplierCode,
                    ProductSku   = TestData.ProductSkuCompanyCodeA,
                    Barcode      = "Barcode2"
                },
            });


            using var writer = new StreamWriter(new MemoryStream());
            var result = Subject.ImportCompanyProductBarcodesFromFileStream(new ImportCompanyProductBarcodeRequest()
            {
                FileStream = writer.BaseStream, CompanyCode = TestData.CompanyCodeA
            });

            //Assert
            Assert.True(result.Success);
            UoW.Verify(m => m.CompanyProductBarcodes.Add(It.IsAny <CompanyProductBarcode>()), Times.Exactly(1));
        }
        public void CompanyProductsAreSaved()
        {
            // Setup
            ImportCompanyProductCsvService.Setup(m => m.GetRecords(It.IsAny <Stream>(), It.IsAny <ClassMap <ImportCompanyProductDto> >()))
            .Returns(new List <ImportCompanyProductDto>()
            {
                new ImportCompanyProductDto
                {
                    ProductName = "ProductName1",
                    ProductSku  = "ProductSku1"
                },
                new ImportCompanyProductDto
                {
                    ProductName = "ProductName2",
                    ProductSku  = "ProductSku"
                },
            });

            using var writer = new StreamWriter(new MemoryStream());
            var result = Subject.ImportCompanyProductsFromFileStream(new ImportCompanyProductRequest()
            {
                FileStream = writer.BaseStream, CompanyCode = TestData.CompanyCodeA
            });

            // Assert
            Assert.True(result.Success);
            UoW.Verify(m => m.CompanyProducts.Add(It.IsAny <CompanyProduct>()), Times.Exactly(2));
        }
        public void SuppliersAreSaved()
        {
            // Setup
            ImportSupplierCsvService.Setup(m => m.GetRecords(It.IsAny <Stream>(), It.IsAny <ClassMap <ImportSupplierDto> >()))
            .Returns(new List <ImportSupplierDto>()
            {
                new ImportSupplierDto
                {
                    SupplierName = "Supplier 1000",
                    SupplierCode = "1000"
                },
                new ImportSupplierDto
                {
                    SupplierName = "Supplier 2000",
                    SupplierCode = "2000"
                },
            });

            using var writer = new StreamWriter(new MemoryStream());
            var result = Subject.ImportSuppliersFromFileStream(new ImportSupplierRequest()
            {
                FileStream = writer.BaseStream, CompanyCode = TestData.CompanyCodeA
            });

            // Assert
            //Assert
            Assert.True(result.Success);
            UoW.Verify(m => m.Suppliers.Add(It.IsAny <Supplier>()), Times.Exactly(2));
        }
Exemple #4
0
        public void CompanyProductIsSaved()
        {
            // Assemble
            var request = TestData.GetCreateCompanyProductRequest();

            // Act
            var result = Subject.CreateCompanyProduct(request);

            // Assert
            Assert.True(result.Success);
            UoW.Verify(m => m.Save(), Times.AtLeastOnce);
        }
Exemple #5
0
        public void SupplierIsSaved()
        {
            // Assemble
            var request = TestData.GetCreateSupplierRequest();

            // Act
            var result = Subject.CreateSupplier(request);

            // Assert
            Assert.True(result.Success);
            UoW.Verify(m => m.Save(), Times.AtLeastOnce);
        }
Exemple #6
0
        public async void GivenModel_ManagerWillUpdateEntityRecord()
        {
            // Arrange
            var manager = new GenericManager <Word>(UoWFactoryMock.Object);

            UoW.Setup(m => m.CreateRepository <IGenericRepository <Word> >().Update(It.IsAny <Word>())).Verifiable();
            // Act
            await manager.UpdateAsync(word).ConfigureAwait(false);

            // Assert
            UoW.Verify(m => m.CreateRepository <IGenericRepository <Word> >().Update(It.Is <Word>(it => it.Id == word.Id)));
        }
Exemple #7
0
        public async void GivenModelId_ManagerFindsEntity()
        {
            // Arrange
            var manager = new GenericManager <Word>(UoWFactoryMock.Object);

            UoW.Setup(m => m.CreateRepository <IGenericRepository <Word> >().FindByIdAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(word)).Verifiable();
            // Act
            await manager.FindByIdAsync(betId).ConfigureAwait(false);

            // Assert
            UoW.Verify(m =>
                       m.CreateRepository <IGenericRepository <Word> >().FindByIdAsync(It.Is <int>(it => it == word.Id)));
        }