public void Seed() { var userId = new Guid("a64a7395-0a29-4847-837d-10bc291df6c8"); var user = new User { Name = "bob", Id = userId }; this.database.Add(userId, user); this.issueAccess.Add(userId, "Sample1", "This is the sample issue1"); this.issueAccess.Add(userId, "Sample2", "This is the sample issue2"); this.issueAccess.Add(userId, "Sample3", "This is the sample issue3"); }
public User Add(string name) { Check.IsNotNull(nameof(name), name); var id = Guid.NewGuid(); var user = new User { Name = name, Id = id }; this.database.Add(id, user); return user; }
public async void Execute_WithValidModel_NotSuccessful() { // arrange RegisterUserModel registrationModel = new RegisterUserModel { Username = "******" }; var existingUser = new User { Name = registrationModel.Username }; this.userAccessMock.Setup(x => x.TryGetByName(registrationModel.Username)).Returns(new Maybe<User>(existingUser)); var command = this.commandRepository.RegisterNewUser(registrationModel); // act var commandResult = await this.CommandExecutor.ExecuteAsync(command); // assert CommandAssert.IsFailure(commandResult); }
public void TryGetByName_KnownName_ReturnUser() { // arrange var user = new User { Id = Guid.NewGuid(), Name = "Bob" }; var users = new ReadOnlyDictionary<Guid, User>(new Dictionary<Guid, User> { { user.Id, user } }); this.databaseMock.Setup(d => d.GetAll<User>()).Returns(users); var nameToSearch = "Bob"; // act var maybeUser = this.userAccess.TryGetByName(nameToSearch); // assert Assert.IsTrue(maybeUser.HasValue); Assert.AreEqual(user.Id, maybeUser.Value.Id); }
public void TryGetByName_KnownNameExistTwice_Throws() { // arrange var user1 = new User { Id = Guid.NewGuid(), Name = "Bob" }; var user2 = new User { Id = Guid.NewGuid(), Name = "boB" }; var users = new ReadOnlyDictionary<Guid, User>( new Dictionary<Guid, User> { { user1.Id, user1 }, { user2.Id, user2 } }); this.databaseMock.Setup(d => d.GetAll<User>()).Returns(users); var nameToSearch = "Bob"; // act / assert Assert.Throws<InvalidOperationException>(() => this.userAccess.TryGetByName(nameToSearch)); }
public void GetAllByUser_WithKnownUserId_ReturnsOk() { // arrange var userId = Guid.NewGuid(); var existingUser = new User {Id = userId}; this.userAccessMock.Setup(x => x.TryGetById(userId)).Returns(new Maybe<User>(existingUser)); this.issueAccessMock.Setup(x => x.GetAllByUserId(userId)).Returns(Enumerable.Empty<Issue>().ToList()); // act var response = this.controller.GetAllByUser(userId); // assert Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); List<IssueModel> issues; Assert.IsTrue(response.TryGetContentValue(out issues)); }
public void Get_WithKnownId_ReturnsOk() { // arrange var id = Guid.NewGuid(); var existingUser = new User {Id = id}; this.userAccessMock.Setup(x => x.TryGetById(id)).Returns(new Maybe<User>(existingUser)); // act var response = this.controller.Get(id); // assert Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); UserModel user; Assert.IsTrue(response.TryGetContentValue(out user)); Assert.AreEqual(id, user.Id); }
public async void Execute_WithCorrectModel_Successful() { // arrange var issueModel = new IssueModel { UserId = Guid.NewGuid(), Title = "title", Content = "content" }; User existingUser = new User { Id = issueModel.UserId }; this.userAccessMock .Setup(x => x.TryGetById(issueModel.UserId)) .Returns(new Maybe<User>(existingUser)); Issue newIssue = new Issue { Id = Guid.NewGuid() }; this.issueAccessMock .Setup(x => x.Add(issueModel.UserId, issueModel.Title, issueModel.Content)) .Returns(newIssue); var command = this.commandRepository.CreateNewIssue(issueModel); // act var commandResult = await this.CommandExecutor.ExecuteAsync(command); // assert CommandAssert.IsSuccessful(commandResult); Assert.AreEqual(newIssue.Id, commandResult.SuccessData.Id); }
public async void Execute_WithValidModelButUserIsKnwon_Successful() { // arrange RegisterUserModel registrationModel = new RegisterUserModel { Username = "******" }; var existingUser = new User { Name = registrationModel.Username }; this.userAccessMock.Setup(x => x.TryGetByName(registrationModel.Username)).Returns(new Maybe<User>(existingUser)); var command = this.commandRepository.RegisterNewUserIfUnknown(registrationModel); // act var commandResult = await this.CommandExecutor.ExecuteAsync(command); // assert CommandAssert.IsSuccessful(commandResult); Assert.AreEqual(registrationModel.Username, commandResult.SuccessData.Name); }