public void Create_ShouldRedirectToIndex_WhenModelIsNotValid() { var entryDataModelRepository = Substitute.For <IRepository <EntryDataModel> >(); var controller = new EntryController(_mapper, entryDataModelRepository); controller.ModelState.AddModelError(Fixture.Create <string>(), Fixture.Create <string>()); var result = controller.Create(Fixture.Create <EntryFormModel>()) as RedirectToRouteResult; Assert.IsFalse(controller.ModelState.IsValid); Assert.IsNotNull(result); entryDataModelRepository.DidNotReceiveWithAnyArgs().Add(Arg.Any <EntryDataModel>()); StringAssert.AreEqualIgnoringCase("Index", result.RouteValues["action"].ToString()); }
public void Create_ShouldRedirectToIndex_WhenAirportIsNull() { var entryDataModelRepository = Substitute.For <IRepository <EntryDataModel> >(); var mapper = Substitute.For <IMapper <EntryFormModel, EntryDataModel> >(); mapper.Map(Arg.Any <EntryFormModel>()).Returns(Fixture.Build <EntryDataModel>().With(x => x.Airport, null).Create()); var controller = new EntryController(mapper, entryDataModelRepository); controller.ModelState.Clear(); var result = controller.Create(Fixture.Create <EntryFormModel>()) as RedirectToRouteResult; Assert.IsTrue(controller.ModelState.IsValid); Assert.IsNotNull(result); entryDataModelRepository.DidNotReceiveWithAnyArgs().Add(Arg.Any <EntryDataModel>()); StringAssert.AreEqualIgnoringCase("Index", result.RouteValues["action"].ToString()); }
public void GivenNavigatorShowCreateEntryView() { INavigationRepository repository = GenerateRepository(); EntryController target = new EntryController(repository); Navigator navigator = GenerateNavigator(); ActionResult actual; actual = target.Create(navigator); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(ViewResult)); ViewResult result = actual as ViewResult; Assert.AreEqual("Create", result.ViewName); EntryViewModel model = result.Model as EntryViewModel; Assert.AreEqual(model.EntryId, 0); Assert.IsTrue(String.IsNullOrEmpty(model.Clue)); Assert.IsTrue(String.IsNullOrEmpty(model.Hint)); }
public void Create_ShouldRedirectToDetail_WhenModelIsValidAndAirportIsNotNull() { var entryDataModelRepository = Substitute.For <IRepository <EntryDataModel> >(); var entryDataModel = Fixture.Create <EntryDataModel>(); var mapper = Substitute.For <IMapper <EntryFormModel, EntryDataModel> >(); mapper.Map(Arg.Any <EntryFormModel>()).Returns(entryDataModel); var controller = new EntryController(mapper, entryDataModelRepository); controller.ModelState.Clear(); var result = controller.Create(Fixture.Create <EntryFormModel>()) as RedirectToRouteResult; Assert.IsTrue(controller.ModelState.IsValid); Assert.IsNotNull(result); entryDataModelRepository.Received().Add(entryDataModel); StringAssert.AreEqualIgnoringCase("Detail", result.RouteValues["action"].ToString()); }
public void GivenEntryViewModelCreateNewEntry() { INavigationRepository repository = GenerateRepository(); EntryController target = new EntryController(repository); EntryViewModel model = Utilities.ObjectFactory.CreateEntry(GenerateNavigator()); repository.Expect(r => r.SaveEntry(model)).Return(true); ActionResult actual; actual = target.Create(model); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(RedirectToRouteResult)); RedirectToRouteResult result = actual as RedirectToRouteResult; Assert.AreEqual("location_default", result.RouteName); Assert.AreEqual("Details", result.RouteValues["Action"]); Assert.AreEqual(model.RegionName, result.RouteValues["RegionName"]); Assert.AreEqual(model.AreaName, result.RouteValues["AreaName"]); Assert.AreEqual(model.LocationName, result.RouteValues["LocationName"]); repository.VerifyAllExpectations(); }
public async Task ShouldCreateAnEntry() { var createEntryRequest = Mother.GenericCreateEntryRequest; var contractEntry = Mother.GenericEntry; var entryResponse = Mother.GenericEntryResponse; _mapper .Setup(m => m.Map <Entry>(createEntryRequest)) .Returns(contractEntry); _mapper .Setup(m => m.Map <EntryResponse>(contractEntry)) .Returns(entryResponse); _entryAccess .Setup(ea => ea.CreateAsync(contractEntry)) .ReturnsAsync(true); var actual = await _sut.Create(createEntryRequest); var result = (CreatedResult)actual; Assert.AreEqual(result.StatusCode, 201); Assert.AreEqual(((EntryResponse)result.Value), entryResponse); }