public void CommentDeleteCommandHandler_Handle() { var observation = FakeObjects.TestObservationWithId("1"); var user = FakeObjects.TestUserWithId(); Comment deleted = null; observation.AddComment(FakeValues.Message, user, FakeValues.CreatedDateTime); using (var session = _store.OpenSession()) { session.Store(observation); session.Store(user); session.SaveChanges(); } using (var session = _store.OpenSession()) { var command = new CommentDeleteCommand() { ContributionId = observation.Id, Id = observation.Comments.ToList()[0].Id }; var commandHandler = new CommentDeleteCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); deleted = session.Load <Observation>(observation.Id).Comments.FirstOrDefault(); } Assert.IsNull(deleted); }
public void ProjectDeleteCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); var project = FakeObjects.TestProjectWithId(); Project deletedTeam = null; var command = new ProjectDeleteCommand() { Id = project.Id, UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(user); session.Store(project); var commandHandler = new ProjectDeleteCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); deletedTeam = session.Load <Project>(project.Id); } Assert.IsNull(deletedTeam); }
public void AccountController_HttpPost_Login_Passing_Valid_Credentials_And_ReturnUrl_Redirects_To_Url() { var user = FakeObjects.TestUserWithId(); var returnUrl = "stuff"; var accountLoginInput = new AccountLoginInput() { Email = FakeValues.Email, Password = FakeValues.Password, ReturnUrl = returnUrl }; using (var session = _documentStore.OpenSession()) { session.Store(user); session.SaveChanges(); } _mockCommandProcessor.Setup(x => x.Process <UserUpdateLastLoginCommand>(It.IsAny <UserUpdateLastLoginCommand>())); var result = _controller.Login(accountLoginInput); Assert.IsInstanceOf <RedirectToRouteResult>(result); Assert.IsTrue(((RedirectToRouteResult)result).RouteValues.ContainsKey("action")); Assert.AreEqual("loggingin", ((RedirectToRouteResult)result).RouteValues["action"].ToString()); Assert.IsTrue(((RedirectToRouteResult)result).RouteValues.ContainsKey("returnUrl")); Assert.AreEqual(returnUrl, ((RedirectToRouteResult)result).RouteValues["returnUrl"].ToString()); }
public void UserIndex_Saves_And_Retrieves_User_By_Email() { var user = FakeObjects.TestUserWithId(); UserProfile indexResult; using (var session = _documentStore.OpenSession()) { session.Store(user); session.SaveChanges(); } using (var session = _documentStore.OpenSession()) { indexResult = session .Advanced .LuceneQuery <User>("User/WithUserIdAndEmail") .WhereContains("Email", user.Email) .WaitForNonStaleResults() .Select(x => new UserProfile() { Id = x.Id, LastLoggedIn = x.LastLoggedIn, Name = x.FirstName + " " + x.LastName }) .FirstOrDefault(); } Assert.IsNotNull(indexResult); Assert.AreEqual(user.FirstName.AppendWith(" ").AppendWith(user.LastName), indexResult.Name); Assert.AreEqual(user.LastLoggedIn, indexResult.LastLoggedIn); }
public void Organisation_Stream_ViewModel() { var organisation = FakeObjects.TestOrganisationWithId(); using (var session = _documentStore.OpenSession()) { session.Store(organisation); session.SaveChanges(); } _controller.SetupFormRequest(); _controller.Stream(new PagingInput() { Id = organisation.Id }); Assert.IsInstanceOf <object>(_controller.ViewData.Model); var jsonData = _controller.ViewData.Model as object; Assert.IsNotNull(jsonData); //Assert.AreEqual(jsonData.Name, organisation.Name); //Assert.AreEqual(jsonData.Description, organisation.Description); //Assert.AreEqual(jsonData.Website, organisation.Website); }
public void AccountController_HttpPost_Login_Passing_Valid_Credentials_Signs_User_In_And_Updates_Last_Logged_In_And_Redirects_To_Logging_In_Action() { var user = FakeObjects.TestUserWithId(); var accountLoginInput = new AccountLoginInput() { Email = FakeValues.Email, Password = FakeValues.Password }; using (var session = _documentStore.OpenSession()) { session.Store(user); session.SaveChanges(); } _mockCommandProcessor.Setup(x => x.Process <UserUpdateLastLoginCommand>(It.IsAny <UserUpdateLastLoginCommand>())); var result = _controller.Login(accountLoginInput); _mockUserContext.Verify(x => x.SignUserIn(It.IsAny <string>(), It.IsAny <bool>()), Times.Once()); _mockCommandProcessor.Verify(x => x.Process <UserUpdateLastLoginCommand>(It.IsAny <UserUpdateLastLoginCommand>()), Times.Once()); Assert.IsInstanceOf <RedirectToRouteResult>(result); Assert.IsTrue(((RedirectToRouteResult)result).RouteValues.ContainsKey("action")); Assert.AreEqual("loggingin", ((RedirectToRouteResult)result).RouteValues["action"].ToString()); }
public void Organisation_Stream_Json() { var organisation = FakeObjects.TestOrganisationWithId(); using (var session = _documentStore.OpenSession()) { session.Store(organisation); session.SaveChanges(); } _controller.SetupAjaxRequest(); var result = _controller.Stream(new PagingInput() { Id = organisation.Id }); Assert.IsInstanceOf <JsonResult>(result); var jsonResult = result as JsonResult; Assert.IsNotNull(jsonResult); Assert.IsInstanceOf <object>(jsonResult.Data); var jsonData = jsonResult.Data as object; Assert.IsNotNull(jsonData); //Assert.AreEqual(jsonData.Name, organisation.Name); //Assert.AreEqual(jsonData.Description, organisation.Description); //Assert.AreEqual(jsonData.Website, organisation.Website); }
public void TeamDeleteCommandHandler_Handle() { var team = FakeObjects.TestTeamWithId(); var user = FakeObjects.TestUserWithId(); Team deletedTeam = null; var command = new TeamDeleteCommand() { Id = team.Id, UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(team); session.Store(user); var commandHandler = new TeamDeleteCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); deletedTeam = session.Load <Team>(team.Id); } Assert.IsNull(deletedTeam); }
public void CreateCampaign_Command_Should_Run_Correctly() { var command = _createCampaignCommandFaker.Generate(); _productRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >())) .ReturnsAsync(true); _campaignRepositoryMock.Setup(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >())) .ReturnsAsync(new List <CampaignEntity>()); _campaignRepositoryMock.Setup(x => x.AnyAsync(MoqHelper.IsExpression <CampaignEntity>(campaign => campaign.Name == command.CampaignName))) .ReturnsAsync(false); _campaignRepositoryMock.Setup(x => x.AddAsync(It.IsAny <CampaignEntity>())) .ReturnsAsync(FakeObjects.GenerateCampaign()); var result = _handler.Handle(command, CancellationToken.None).Result; result.Campaign.Should().NotBeNull(); _productRepositoryMock.Verify(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()), Times.Once); _campaignRepositoryMock.Verify(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once); _campaignRepositoryMock.Verify(x => x.AnyAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once); _campaignRepositoryMock.Verify(x => x.AddAsync(It.IsAny <CampaignEntity>()), Times.Once); }
public void User_UpdateEmail_WithValidEmail() { Assert.IsTrue(FakeObjects.TestUser() .UpdateEmail("*****@*****.**") .Email .Equals("*****@*****.**")); }
public void WatchlistCreateCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); Watchlist newValue = null; var command = new WatchlistCreateCommand() { UserId = user.Id, Name = FakeValues.Name, JsonQuerystring = FakeValues.QuerystringJson }; using (var session = _store.OpenSession()) { session.Store(user); var commandHandler = new WatchlistCreateCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); newValue = session.Query <Watchlist>().FirstOrDefault(); } Assert.IsNotNull(newValue); Assert.AreEqual(command.Name, newValue.Name); Assert.AreEqual(command.JsonQuerystring, newValue.QuerystringJson); }
public void CreateOrder_Command_Should_Run_Correctly_If_Product_DoesNot_Have_Campaign() { _productRepositoryMock.Setup(x => x.FindOneAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >())) .ReturnsAsync(FakeObjects.GenerateProduct()); _productRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <ProductEntity>())) .Returns(Task.CompletedTask); _campaignRepositoryMock.Setup(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >())) .ReturnsAsync(new List <CampaignEntity>()); _campaignRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <CampaignEntity>())) .Returns(Task.CompletedTask); _orderRepositoryMock.Setup(x => x.AddAsync(It.IsAny <OrderEntity>())). ReturnsAsync(FakeObjects.GenerateOrder()); var result = _handler.Handle(_createOrderFaker.Generate(), CancellationToken.None).Result; _productRepositoryMock.Verify(x => x.FindOneAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()), Times.Once); _productRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <ProductEntity>()), Times.Once); _campaignRepositoryMock.Verify(x => x.FindAsync(It.IsAny <Expression <Func <CampaignEntity, bool> > >()), Times.Once); _campaignRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <CampaignEntity>()), Times.Never); _orderRepositoryMock.Verify(x => x.AddAsync(It.IsAny <OrderEntity>()), Times.Once); result.Should().NotBeNull(); }
public void ObservationNoteDeleteCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); var observation = FakeObjects.TestObservationWithId(); var observationNote = FakeObjects.TestObservationNoteWithId(); ObservationNote deletedTeam = null; var command = new ObservationNoteDeleteCommand() { Id = observationNote.Id, UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(user); session.Store(observation); session.Store(observationNote); var commandHandler = new ObservationNoteDeleteCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); deletedTeam = session.Load <ObservationNote>(observationNote.Id); } Assert.IsNull(deletedTeam); }
public void UsersController_Update_Get_Returns_View() { var user = FakeObjects.TestUserWithId(); using (var session = _documentStore.OpenSession()) { session.Store(user); session.SaveChanges(); } _mockUserContext.Setup(x => x.GetAuthenticatedUserId()).Returns(user.Id); var result = _controller.Update(new UserUpdateInput()) as object; Assert.IsNotNull(result); Assert.IsInstanceOf <object>(result); //Assert.IsNotNull(modelData); //Assert.AreEqual(user.Description, modelData.Description); //Assert.AreEqual(user.FirstName, modelData.FirstName); //Assert.AreEqual(user.LastName, modelData.LastName); //Assert.AreEqual(user.Email, modelData.Email); }
public void OrganisationDeleteCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); var organisation = FakeObjects.TestOrganisationWithId(); Organisation deleted = null; var command = new OrganisationDeleteCommand() { Id = organisation.Id, UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(user); session.Store(organisation); session.SaveChanges(); var commandHandler = new OrganisationDeleteCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); deleted = session.Load <Organisation>(organisation.Id); } Assert.IsNull(deleted); }
public void Observation_UpdateComment() { var observation = TestObservation(); var comment = FakeObjects.TestCommentWithId(); var user = FakeObjects.TestUserWithId(); var createdDateTime = DateTime.UtcNow.AddDays(-1); var modifiedDateTime = DateTime.UtcNow; observation.Discussion.AddComment( comment.Message, user, createdDateTime ); observation.Discussion.UpdateComment( comment.Id, FakeValues.Comment.AppendWith("new"), user, modifiedDateTime ); var updatedComment = observation.Discussion.Comments.ToList()[0]; Assert.AreEqual(modifiedDateTime, updatedComment.EditedOn); Assert.AreEqual(FakeValues.Comment.AppendWith("new"), updatedComment.Message); }
public void MediaResourceDeleteCommandHandler_Handle() { var mediaResource = FakeObjects.TestMediaResourceWithId(); var user = FakeObjects.TestUserWithId(); MediaResource deleted = null; var command = new MediaResourceDeleteCommand() { Id = mediaResource.Id, UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(mediaResource); session.Store(user); var commandHandler = new MediaResourceDeleteCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); deleted = session.Load <MediaResource>(mediaResource.Id); } Assert.IsNull(deleted); }
public void UserUpdateLastLoginCommandHandler_Handle() { DateTime originalValue; DateTime newValue; using (var session = _store.OpenSession()) { var user = FakeObjects.TestUserWithId(); user.UpdateLastLoggedIn(); originalValue = user.LastLoggedIn; session.Store(user); session.SaveChanges(); // wait a second. Thread.Sleep(1000); var userUpdateLastLoginCommandHandler = new UserUpdateLastLoginCommandHandler(session); userUpdateLastLoginCommandHandler.Handle(new UserUpdateLastLoginCommand() { Email = user.Email }); session.SaveChanges(); newValue = session.Load <User>(user.Id).LastLoggedIn; } Assert.AreNotEqual(originalValue, newValue); Assert.Greater(newValue, originalValue); }
public void Team_Stream_As_Json() { var team = FakeObjects.TestTeamWithId(); var user = FakeObjects.TestUserWithId(); using (var session = _documentStore.OpenSession()) { session.Store(user); session.Store(team); session.SaveChanges(); } _controller.SetupAjaxRequest(); var result = _controller.Stream(new PagingInput() { Id = team.Id }); Assert.IsInstanceOf <JsonResult>(result); var jsonResult = result as JsonResult; Assert.IsNotNull(jsonResult); //Assert.IsInstanceOf<TeamIndex>(jsonResult.Data); //var jsonData = jsonResult.Data as TeamIndex; //Assert.IsNotNull(jsonData); //Assert.AreEqual(jsonData.Team, team); }
public void WatchlistDeleteCommandHandler_Handle() { var watchlist = FakeObjects.TestWatchlistWithId(); var user = FakeObjects.TestUserWithId(); Watchlist deletedWatchlist = null; var command = new WatchlistDeleteCommand() { Id = watchlist.Id, UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(watchlist); session.Store(user); var commandHandler = new WatchlistDeleteCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); deletedWatchlist = session.Load <Watchlist>(watchlist.Id); } Assert.IsNull(deletedWatchlist); }
public void TeamUpdateCommandHandlerTest_Handle() { var originalValue = FakeObjects.TestTeamWithId(); var user = FakeObjects.TestUserWithId(); Team newValue; var command = new TeamUpdateCommand() { Description = FakeValues.Description.PrependWith("new"), Id = originalValue.Id, Name = FakeValues.Name.PrependWith("new"), UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(user); session.Store(originalValue); var commandHandler = new TeamUpdateCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); newValue = session.Load <Team>(originalValue.Id); } Assert.IsNotNull(newValue); Assert.AreEqual(command.Description, newValue.Description); Assert.AreEqual(command.Name, newValue.Name); Assert.AreEqual(command.Website, newValue.Website); }
public void Observation_GetOne_As_Json() { var user = FakeObjects.TestUserWithId(); var observation = FakeObjects.TestObservationWithId(); using (var session = _documentStore.OpenSession()) { session.Store(user); session.Store(observation); session.SaveChanges(); } _controller.SetupAjaxRequest(); var result = _controller.GetOne(new IdInput() { Id = observation.Id }); Assert.IsInstanceOf <JsonResult>(result); var jsonResult = result as JsonResult; Assert.IsNotNull(jsonResult); //Assert.IsInstanceOf<ObservationIndex>(jsonResult.Data); //var jsonData = jsonResult.Data as ObservationIndex; //Assert.IsNotNull(jsonData); //Assert.AreEqual(observation, jsonData.Observation); }
public void Observation_GetOne_As_ViewModel() { var user = FakeObjects.TestUserWithId(); var observation = FakeObjects.TestObservationWithId(); using (var session = _documentStore.OpenSession()) { session.Store(user); session.Store(observation); session.SaveChanges(); } _controller.SetupFormRequest(); _controller.GetOne(new IdInput() { Id = observation.Id }); //Assert.IsInstanceOf<ObservationIndex>(_controller.ViewData.Model); //var viewModel = _controller.ViewData.Model as ObservationIndex; //Assert.IsNotNull(viewModel); //Assert.AreEqual(viewModel.Observation, observation); }
public void MediaResourceCreateCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); MediaResource newValue = null; var command = new MediaResourceCreateCommand() { UserId = user.Id, UploadedOn = FakeValues.CreatedDateTime, OriginalFileName = FakeValues.Filename, Stream = null, Usage = FakeValues.Usage }; using (var session = _store.OpenSession()) { session.Store(user); var commandHandler = new MediaResourceCreateCommandHandler(session, _mockMediaFilePathService.Object); commandHandler.Handle(command); session.SaveChanges(); newValue = session.Query <MediaResource>().FirstOrDefault(); } Assert.IsNotNull(newValue); Assert.AreEqual(command.UploadedOn, newValue.UploadedOn); //Assert.AreEqual(user.DenormalisedUserReference(), newValue.CreatedByUser); }
public void WatchlistUpdateCommandHandlerTest_Handle() { var originalValue = FakeObjects.TestWatchlistWithId(); var user = FakeObjects.TestUserWithId(); Watchlist newValue; var command = new WatchlistUpdateCommand() { Id = originalValue.Id, Name = FakeValues.Name.PrependWith("new"), JsonQuerystring = FakeValues.QuerystringJson.PrependWith("new"), UserId = user.Id }; using (var session = _store.OpenSession()) { session.Store(user); session.Store(originalValue); var commandHandler = new WatchlistUpdateCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); newValue = session.Load <Watchlist>(originalValue.Id); } Assert.IsNotNull(newValue); Assert.AreEqual(command.Name, newValue.Name); Assert.AreEqual(command.JsonQuerystring, newValue.QuerystringJson); }
public void OrganisationCreateCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); Organisation newValue = null; var command = new OrganisationCreateCommand() { Description = FakeValues.Description, Name = FakeValues.Name, UserId = user.Id, Website = FakeValues.Website }; using (var session = _store.OpenSession()) { session.Store(user); session.SaveChanges(); var commandHandler = new OrganisationCreateCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); newValue = session.Query <Organisation>().FirstOrDefault(); } Assert.IsNotNull(newValue); Assert.AreEqual(command.Website, newValue.Website); Assert.AreEqual(command.Description, newValue.Description); Assert.AreEqual(command.Name, newValue.Name); }
public void Project_UpdateDetails() { var createdDateTime = DateTime.UtcNow; var testProject = new Project( FakeObjects.TestUserWithId(), FakeValues.Name, FakeValues.Description, FakeValues.Website, null, createdDateTime ); testProject.UpdateDetails( FakeObjects.TestUser(), FakeValues.Name.AppendWith(additionalString), FakeValues.Description.AppendWith(additionalString), FakeValues.Website.AppendWith(additionalString), null ); Assert.AreEqual(testProject.Name, FakeValues.Name.AppendWith(additionalString)); Assert.AreEqual(testProject.Description, FakeValues.Description.AppendWith(additionalString)); Assert.AreEqual(testProject.Website, FakeValues.Website.AppendWith(additionalString)); }
public void OrganisationUpdateCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); var organisation = FakeObjects.TestOrganisationWithId(); Organisation newValue = null; var command = new OrganisationUpdateCommand() { Description = FakeValues.Description.PrependWith("new"), Id = organisation.Id, Name = FakeValues.Name.PrependWith("new"), UserId = user.Id, Website = FakeValues.Website.PrependWith("new") }; using (var session = _store.OpenSession()) { session.Store(user); session.Store(organisation); session.SaveChanges(); var commandHandler = new OrganisationUpdateCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); newValue = session.Load <Organisation>(organisation.Id); } Assert.IsNotNull(newValue); Assert.AreEqual(command.Description, newValue.Description); Assert.AreEqual(command.Name, newValue.Name); Assert.AreEqual(command.Website, newValue.Website); }
public void ProjectCreateCommandHandler_Handle() { var user = FakeObjects.TestUserWithId(); var team = FakeObjects.TestTeamWithId(); Project newValue = null; var command = new ProjectCreateCommand() { UserId = user.Id, Description = FakeValues.Description, Name = FakeValues.Name, TeamId = team.Id }; using (var session = _store.OpenSession()) { session.Store(user); session.Store(team); session.SaveChanges(); var commandHandler = new ProjectCreateCommandHandler(session); commandHandler.Handle(command); session.SaveChanges(); newValue = session.Query <Project>().FirstOrDefault(); } Assert.IsNotNull(newValue); Assert.AreEqual(command.Name, newValue.Name); Assert.AreEqual(command.Description, newValue.Description); //Assert.AreEqual(team.DenormalisedNamedDomainModelReference<Team>(), newValue.Team); }
public void User_UpdateEmail_WithInValidEmail() { Assert.IsTrue( BowerbirdThrows.Exception <DesignByContractException>(() => FakeObjects.TestUser() .UpdateEmail(FakeValues.InvalidEmail) )); }