public void Get_NotLoggedIn_ReturnsUnauthorized() { var loginRepo = new MockLoginRepository(); var userRepo = new MockUserRepository(); var contactRepo = new Mock <IContactRepository>(); ContactsController controller = new ContactsController(contactRepo.Object, userRepo, loginRepo); Guid key = Guid.NewGuid(); IActionResult result = controller.Get(Auth.Get(key)); UnauthorizedObjectResult unauth = result as UnauthorizedObjectResult; Assert.IsNotNull(unauth, "Result is not unauthorized"); Assert.IsNotNull(unauth.Value); Assert.IsTrue(unauth.Value is ErrorResponse); Assert.IsTrue(!string.IsNullOrEmpty((unauth.Value as ErrorResponse).Message)); }
public void Post_Succeeds() { var loginRepo = new MockLoginRepository(); var userRepo = new MockUserRepository(); var contactRepo = new Mock <IContactRepository>(); ContactsController controller = new ContactsController(contactRepo.Object, userRepo, loginRepo); Guid key = Guid.NewGuid(); userRepo.CreateUser(new UserWriteDbo { CreatedAt = DateTime.UtcNow }); loginRepo.CreateLogin(new LoginDbo { Id = key.ToByteArray(), UserId = 1 }); IActionResult result = controller.Post(new NewContactRequest { Name = "A Name" }, Auth.Get(key)); Assert.IsNotNull(result); Assert.IsTrue(result is OkResult); }