public void Update_State_By_Admin_Correctly() { var currentEbatchSheet = new EbatchSheetEntity.EbatchSheet() { CurrentState = EbatchState.ProductionReview }; var updateRequest = new UpdateEbatchSheetCommand() { CurrentState = EbatchState.WarehouseReview }; var updateResponse = new CosmosResponse <EbatchSheetEntity.EbatchSheet>(currentEbatchSheet, new ResourceResponse <Document>()); _cosmosStore.Setup(f => f.FindAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(currentEbatchSheet); _cosmosStore.Setup(f => f.UpdateAsync(It.IsAny <EbatchSheetEntity.EbatchSheet>(), null)).ReturnsAsync(updateResponse); _httpContext.Setup(x => x.HttpContext.User.IsInRole(It.IsAny <string>())).Returns(true); var updateHandler = new UpdateEbatchSheetCommandHandler(_cosmosStore.Object, _httpContext.Object, _updateLogger.Object, _mailSender.Object); var result = updateHandler.Handle(updateRequest, CancellationToken.None); Assert.Equal(updateRequest.CurrentState.Value, updateResponse.Entity.CurrentState.Value); }
public void Update_Any_State_By_User_Failed() { var currentEbatchSheet = new EbatchSheetEntity.EbatchSheet() { CurrentState = EbatchState.ProductionReview }; var updateRequest = new UpdateEbatchSheetCommand() { CurrentState = EbatchState.WarehouseReview }; var updateResponse = new CosmosResponse <EbatchSheetEntity.EbatchSheet>(currentEbatchSheet, new ResourceResponse <Document>()); _cosmosStore.Setup(f => f.FindAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(currentEbatchSheet); _cosmosStore.Setup(f => f.UpdateAsync(It.IsAny <EbatchSheetEntity.EbatchSheet>(), null)).ReturnsAsync(updateResponse); _httpContext.Setup(x => x.HttpContext.User.IsInRole(It.IsAny <string>())).Returns(false); var updateHandler = new UpdateEbatchSheetCommandHandler(_cosmosStore.Object, _httpContext.Object, _updateLogger.Object, _mailSender.Object); Assert.ThrowsAsync <InvalidStateChange>(() => updateHandler.Handle(updateRequest, CancellationToken.None)); }