public IResult <string> UpdateProductionBatch(IUpdateProductionBatchParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var parametersResult = parameters.ToParsedParameters(); if (!parametersResult.Success) { return(parametersResult.ConvertTo <string>()); } var result = new UpdateProductionBatchCommand(_productionUnitOfWork).Execute(_timeStamper.CurrentTimeStamp, parametersResult.ResultingObject); if (!result.Success) { return(result.ConvertTo <string>()); } _productionUnitOfWork.Commit(); return(SyncParameters.Using(new SuccessResult <string>(parameters.ProductionBatchKey), parametersResult.ResultingObject.ProductionBatchKey)); }
public IResult <string> UpdateProductionBatch(IUpdateProductionBatchParameters parameters) { try { var result = _productionServiceProvider.UpdateProductionBatch(parameters); if (!result.Success) { return(result.ConvertTo <string>()); } return(result.ConvertTo(result.ResultingObject)); } catch (Exception ex) { _exceptionLogger.LogException(ex); return(new FailureResult <string>(null, ex.GetInnermostException().Message)); } }
public void CallsServiceAsExpected() { // arrange const string id = "12345"; var input = Fixture.Create <UpdateProductionBatchParameters>(); IUpdateProductionBatchParameters actualParams = null; MockPackScheduleService.Setup(m => m.UpdateProductionBatch(input)) .Callback((IUpdateProductionBatchParameters i) => actualParams = i) .Returns(new SuccessResult <string>("key")); // act ControllerUnderTest.Put(id, input); // assert MockPackScheduleService.Verify(m => m.UpdateProductionBatch(input), Times.Once()); Assert.AreEqual(id, actualParams.ProductionBatchKey); }
public void UtilizedUserIdentityProvider() { // arrange const string id = "12345"; var input = Fixture.Create <UpdateProductionBatchParameters>(); IUpdateProductionBatchParameters actualParams = null; MockUserIdentityProvider.Setup(m => m.SetUserIdentity(input)) .Callback((IUserIdentifiable i) => i.UserToken = "user token"); MockPackScheduleService.Setup(m => m.UpdateProductionBatch(input)) .Callback((IUpdateProductionBatchParameters i) => actualParams = i) .Returns(new SuccessResult <string>("key", null)); // act ControllerUnderTest.Put(id, input); // assert MockUserIdentityProvider.Verify(m => m.SetUserIdentity(input), Times.Once()); Assert.AreEqual("user token", actualParams.UserToken); }
internal static IResult <UpdateProductionBatchCommandParameters> ToParsedParameters(this IUpdateProductionBatchParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var productionBatchKey = KeyParserHelper.ParseResult <ILotKey>(parameters.ProductionBatchKey); if (!productionBatchKey.Success) { return(productionBatchKey.ConvertTo <UpdateProductionBatchCommandParameters>()); } return(new SuccessResult <UpdateProductionBatchCommandParameters>(new UpdateProductionBatchCommandParameters { Parameters = parameters, ProductionBatchKey = new LotKey(productionBatchKey.ResultingObject) })); }