public async Task WhenJsonSourceIsNotValid_HTT500_CanReturnAnEmptyArray() { //Arrange var registrations = new List <OwnerInfo>(); var stubILogger = StubHelper.StubILogger <RegistrationController>(); var stubIFetchService = StubHelper.StubIFetchService; stubIFetchService.Setup(x => x.GetRegistrations()) .Returns(Task.FromResult(registrations)); var stubIRenderService = StubHelper.StubIRenderService; var stubIVewingService = StubHelper.StubIVewingService; var testedService = new RegistrationController(stubILogger.Object, stubIFetchService.Object, stubIVewingService.Object, stubIRenderService.Object); //Act var result = await testedService.GetAll(); var actual = result as NoContentResult; //Assert Assert.Equal((int)HttpStatusCode.NoContent, actual.StatusCode); }
public async Task WhenJsonSourceIsValid_CanReturnAllRegistrations() { //Arrange var registrations = FakeModels.Registrations; var testViewData = FakeModels.CatsViewForRender; var renderingData = FakeModels.RenderingData; var stubILogger = StubHelper.StubILogger <RegistrationController>(); var stubIFetchService = StubHelper.StubIFetchService; stubIFetchService.Setup(x => x.GetRegistrations()) .Returns(Task.FromResult(registrations)); var stubIVewingService = StubHelper.StubIVewingService; stubIVewingService.Setup(x => x.ViewRegistrations(It.IsAny <List <OwnerInfo> >(), ViewType.CatsUnderOnwersGender)) .Returns(testViewData); var stubIRenderService = StubHelper.StubIRenderService; stubIRenderService.Setup(x => x.RenderRegistrations(It.IsAny <List <ResultFormat> >())) .Returns(renderingData); var testedService = new RegistrationController(stubILogger.Object, stubIFetchService.Object, stubIVewingService.Object, stubIRenderService.Object); //Act var result = await testedService.GetAll(); var actual = result as ContentResult; //Assert Assert.Equal((int)HttpStatusCode.OK, actual.StatusCode); }
public void GetAll_ReturnJsonResult() { //Arrange RegistrationController registrationController = new RegistrationController(null, null, new RegistrationRepository(new ContactManagementApplicationContext())); //Act var result = registrationController.GetAll(); //Assert Assert.IsType <JsonResult>(result); }
public void GetAll_ReturnAllItems() { //Arrange RegistrationController registrationController = new RegistrationController(null, null, new RegistrationRepository(new ContactManagementApplicationContext())); //Act JsonResult result = registrationController.GetAll() as JsonResult; //Assert JObject jObj = (JObject)JsonConvert.DeserializeObject(result.ToString()); Assert.Equal(5, jObj.Count); }