internal IResult <AdditiveProduct> CreateAdditiveProduct(CreateAdditiveProductParameters parameters, DateTime timeStamp)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var additiveType = _productUnitOfWork.AdditiveTypeRepository.FindByKey(parameters.AdditiveTypeKey);

            if (additiveType == null)
            {
                return(new InvalidResult <AdditiveProduct>(null, string.Format(UserMessages.AdditiveTypeNotFound, parameters.AdditiveTypeKey.KeyValue)));
            }

            var productResult = CreateProduct(parameters.Parameters, ProductTypeEnum.Additive);

            if (!productResult.Success)
            {
                return(productResult.ConvertTo((AdditiveProduct)null));
            }
            var product = productResult.ResultingObject;

            var additiveProduct = new AdditiveProduct
            {
                Id             = product.Id,
                AdditiveTypeId = parameters.AdditiveTypeKey.AdditiveTypeKey_AdditiveTypeId,

                Product = product
            };

            additiveProduct = _productUnitOfWork.AdditiveProductRepository.Add(additiveProduct);

            return(new SuccessResult <AdditiveProduct>(additiveProduct));
        }
Esempio n. 2
0
            public void Creates_new_tblProduct_record_as_expected()
            {
                //Arrange
                var additiveType = RVCUnitOfWork.AdditiveTypeRepository.FindBy(t => true);

                if (additiveType == null)
                {
                    Assert.Inconclusive("No suitable AdditiveType to test.");
                }

                var parameters = new CreateAdditiveProductParameters
                {
                    UserToken       = TestUser.UserName,
                    AdditiveTypeKey = additiveType.ToAdditiveTypeKey(),
                    ProductName     = "Test Additive Product",
                    ProductCode     = "12345"
                };

                //Act
                var result = Service.CreateAdditiveProduct(parameters);

                result.AssertSuccess();
                var resultString = GetKeyFromConsoleString(ConsoleOutput.SynchedTblProduct);

                //Assert
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var prodId = int.Parse(resultString);

                using (var oldContext = new RioAccessSQLEntities())
                {
                    var tblProduct = oldContext.tblProducts.FirstOrDefault(p => p.ProdID == prodId);
                    Assert.AreEqual(parameters.ProductName, tblProduct.Product);
                    Assert.AreEqual(int.Parse(parameters.ProductCode), tblProduct.ProdID);
                    Assert.AreEqual(additiveType.Id, tblProduct.IngrID);
                }
            }