public void AttemptsToGetPackScheduleByPSNumOnInvalid() { // arrange const string PSNum = "123456"; var serviceQuery = Fixture.CreateMany <PackScheduleSummaryReturn>().ToList(); serviceQuery.First().PSNum = int.Parse(PSNum); var expectedPackScheduleKey = serviceQuery.First().PackScheduleKey; var expectedResult = Fixture.Create <IPackScheduleDetailReturn>(); MockPackScheduleService .Setup(m => m.GetPackSchedule(PSNum)) .Returns(new InvalidResult <IPackScheduleDetailReturn>()); MockPackScheduleService .Setup(m => m.GetPackSchedule(expectedPackScheduleKey)) .Returns(new SuccessResult <IPackScheduleDetailReturn>(expectedResult)); MockPackScheduleService.Setup(m => m.GetPackSchedules()) .Returns(new SuccessResult <IQueryable <IPackScheduleSummaryReturn> >(serviceQuery.AsQueryable())); // act SystemUnderTest.Get(PSNum); // assert MockPackScheduleService.Verify(m => m.GetPackSchedule(expectedPackScheduleKey), Times.Once()); }
public void CallsServiceAsExpected() { // arrange var inputParams = Fixture.Create <CreatePackSchedule>(); // act SystemUnderTest.Post(inputParams); // assert MockPackScheduleService.Verify(m => m.CreatePackSchedule(It.IsAny <ICreatePackScheduleParameters>()), Times.Once()); }
public void CallsServiceAsExpected() { // arrange const string key = "1234-5"; var input = Fixture.Create <UpdatePackScheduleParameters>(); // act SystemUnderTest.Put(key, input); // assert MockPackScheduleService.Verify(m => m.UpdatePackSchedule(It.IsAny <IUpdatePackScheduleParameters>()), Times.Once()); Assert.AreEqual(key, input.PackScheduleKey); }
public void CallsServiceAsExpected() { // arrange var exptectedServiceResponse = Fixture.CreateMany <IPackScheduleSummaryReturn>().AsQueryable(); MockPackScheduleService.Setup(m => m.GetPackSchedules()) .Returns(new SuccessResult <IQueryable <IPackScheduleSummaryReturn> >(exptectedServiceResponse)); // act SystemUnderTest.Get(); // assert MockPackScheduleService.Verify(m => m.GetPackSchedules()); }
public void CallsServiceAsExpected() { // arrange const string key = "key"; MockPackScheduleService.Setup(m => m.RemoveProductionBatch(key)) .Returns(new SuccessResult <string>()); // act ControllerUnderTest.Delete(key); // assert MockPackScheduleService.Verify(m => m.RemoveProductionBatch(key)); }
public void CallsServiceAsExpected() { // arrange const string expectedPackScheduleKey = "123456-789"; MockPackScheduleService .Setup(m => m.GetPackSchedule(expectedPackScheduleKey)) .Returns(new SuccessResult <IPackScheduleDetailReturn>(Fixture.Create <IPackScheduleDetailReturn>())); // act SystemUnderTest.Get(expectedPackScheduleKey); // assert MockPackScheduleService.Verify(m => m.GetPackSchedule(expectedPackScheduleKey), Times.Once()); }
public void CallsServiceAsExpected() { // arrange var input = Fixture.Create <CreateProductionBatchDto>(); var @return = Fixture.Create <CreateProductonBatchReturn>(); MockPackScheduleService.Setup(m => m.CreateProductionBatch(It.IsAny <CreateProductionBatchParameters>())) .Returns(new SuccessResult <ICreateProductionBatchReturn>(@return)); // act ControllerUnderTest.Post(input); // assert MockPackScheduleService.Verify(m => m.CreateProductionBatch(It.IsAny <CreateProductionBatchParameters>()), Times.Once()); }
public void Returns400WithoutCallingServiceIfModelStateIsInvalid() { // arrange const string key = "1234-5"; var input = Fixture.Create <UpdatePackScheduleParameters>(); SystemUnderTest.ModelState.AddModelError("", "error"); // act var response = SystemUnderTest.Put(key, input); // assert Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); MockPackScheduleService.Verify(m => m.UpdatePackSchedule(It.IsAny <IUpdatePackScheduleParameters>()), Times.Never()); }
public void ReturnsServiceResultObjectOnSuccess() { // arrange var expectedPackSchedule = Fixture.Create <IProductionBatchDetailReturn>(); const string key = "03 14 010 01"; MockPackScheduleService.Setup(m => m.GetProductionBatch(key)) .Returns(new SuccessResult <IProductionBatchDetailReturn>(expectedPackSchedule)); // act var result = ControllerUnderTest.Get(key); // assert MockPackScheduleService.Verify(m => m.GetProductionBatch(key)); Assert.AreEqual(expectedPackSchedule, result); }
public void ThrowsInternalServerErrorOnFailure() { // arrange var input = Fixture.Create <CreateProductionBatchDto>(); MockPackScheduleService .Setup(m => m.CreateProductionBatch(It.IsAny <CreateProductionBatchParameters>())) .Returns(new FailureResult <ICreateProductionBatchReturn>()); // act var response = ControllerUnderTest.Post(input); // assert Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); MockPackScheduleService.Verify(m => m.CreateProductionBatch(It.IsAny <CreateProductionBatchParameters>()), Times.Once()); }
public void CallsServiceAsExpected() { // arrange const string key = "1234"; IRemovePackScheduleParameters actualParameters = null; MockPackScheduleService.Setup(m => m.RemovePackSchedule(It.IsAny <IRemovePackScheduleParameters>())) .Callback((IRemovePackScheduleParameters p) => actualParameters = p) .Returns(new SuccessResult <string>()); // act SystemUnderTest.Delete(key); // assert Assert.IsNotNull(actualParameters); MockPackScheduleService.Verify(m => m.RemovePackSchedule(It.IsAny <IRemovePackScheduleParameters>()), Times.Once()); Assert.AreEqual(actualParameters.PackScheduleKey, key); }
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 ThrowsBadRequestExceptionOnModelError() { // arrange var input = Fixture.Create <CreateProductionBatchDto>(); MockPackScheduleService.Setup(m => m.CreateProductionBatch(It.IsAny <CreateProductionBatchParameters>())) .Verifiable(); ControllerUnderTest.ModelState.AddModelError("", "error"); try { // act ControllerUnderTest.Post(input); } catch (HttpResponseException ex) { // assert Assert.AreEqual(HttpStatusCode.BadRequest, ex.Response.StatusCode); MockPackScheduleService.Verify(m => m.CreateProductionBatch(It.IsAny <CreateProductionBatchParameters>()), Times.Never()); throw; } }