public async Task Create_ReturnsAsActionResult_WithCreateDemandPage() { var result = await _controller.Create(); Assert.Pass(); Assert.IsNotNull(result as IActionResult); }
public async Task And_Exception_Then_Returns_Bad_Request( int courseId, string locationName, [Frozen] Mock <IMediator> mockMediator, [Greedy] DemandController controller) { mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetRegisterDemandQuery>(), It.IsAny <CancellationToken>())) .Throws <InvalidOperationException>(); var controllerResult = await controller.Create(courseId, locationName) as BadRequestResult; controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest); }
public void Create() { var memoryStore = new List <Demand>(); Demand demandStub = new Demand { Id = 1 }; var mock = new Mock <IRepository <Demand> >(); mock.Setup(repo => repo.GetAll()).Returns(memoryStore.AsQueryable()); mock.Setup(repo => repo.Create(It.IsAny <Demand>())).Returns((Demand demand) => { demand.Id = 1; memoryStore.Add(demand); return(demand); }); var factoryMock = new Mock <IRepositoryFactory>(); factoryMock.Setup(f => f.GetRepository <Demand>()).Returns(mock.Object); _demandController = new DemandController(factoryMock.Object); var emptyJson = _demandController.GetAll(); Assert.IsNotNull(emptyJson); var emptyStore = emptyJson.Value as List <Demand>; Assert.IsNotNull(emptyStore); Assert.AreEqual(emptyStore.Count, 0); var json = _demandController.Create(demandStub); Assert.IsNotNull(json); var result = json.Value as Demand; Assert.NotNull(result); Assert.AreEqual(result.Id, 1); Assert.AreEqual(result.Client, demandStub.Client); var notEmptyJson = _demandController.GetAll(); Assert.IsNotNull(notEmptyJson); var notEmptyStore = notEmptyJson.Value as List <Demand>; Assert.IsNotNull(notEmptyStore); Assert.AreEqual(notEmptyStore.Count, 1); }
public async Task Then_Gets_Training_Course_And_Location_From_Mediator( int courseId, string locationName, GetRegisterDemandResult mediatorResult, [Frozen] Mock <IMediator> mockMediator, [Greedy] DemandController controller) { mockMediator .Setup(mediator => mediator.Send( It.Is <GetRegisterDemandQuery>(c => c.CourseId.Equals(courseId) && c.LocationName.Equals(locationName)), It.IsAny <CancellationToken>())) .ReturnsAsync(mediatorResult); var controllerResult = await controller.Create(courseId, locationName) as ObjectResult; Assert.IsNotNull(controllerResult); controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK); var model = controllerResult.Value as GetCourseResponse; Assert.IsNotNull(model); model.TrainingCourse.Should().BeEquivalentTo((GetCourseListItem)mediatorResult.Course); model.Location.Should().BeEquivalentTo((GetLocationSearchResponseItem)mediatorResult.Location); }