예제 #1
0
        public ClaimServiceUT()
        {
            var testUtils = new TestingUtils();

            claimService = new ClaimService();

            user1 = testUtils.CreateUserInDb();
            user2 = testUtils.CreateUserInDb();

            service1 = testUtils.CreateServiceInDb(true);
            service2 = testUtils.CreateServiceInDb(true);

            _db = new DatabaseContext();

            claim1 = testUtils.CreateClaim(user1, service1, user2);
        }
        public void DeleteUser_Authorized_200()
        {
            var controller = new UserManagementController();
            var admin      = _ut.CreateUserObject();

            admin.IsAdministrator = true;
            var adminSession = _ut.CreateSessionObject(admin);

            _ut.CreateSessionInDb(adminSession);
            var userToDelete = _ut.CreateUserInDb().Id;

            var expectedStatusCode = HttpStatusCode.OK;

            var endpoint = API_Route_Local + "/user/delete/{userId}";

            controller.Request = new HttpRequestMessage
            {
                RequestUri = new Uri(endpoint)
            };
            controller.Request.Headers.Add("token", adminSession.Token);

            IHttpActionResult actionresult = controller.DeleteUser(userToDelete.ToString());

            Assert.IsInstanceOfType(actionresult, typeof(NegotiatedContentResult <string>));
            var contentresult = actionresult as NegotiatedContentResult <string>;

            Assert.AreEqual(expectedStatusCode, contentresult.StatusCode);

            // persistence test
            using (var _db = _ut.CreateDataBaseContext())
            {
                var getUser = _db.Users.Find(userToDelete);
                Assert.IsNull(getUser);
            }
        }
예제 #3
0
        public void Delete_User_Success()
        {
            // Arrange
            newUser = tu.CreateUserInDb();

            var expectedResponse = newUser;

            using (_db = tu.CreateDataBaseContext())
            {
                // Act
                us = new UserService(_db);
                var response = us.DeleteUser(newUser.Id);
                _db.SaveChanges();
                var result = _db.Users.Find(expectedResponse.Id);

                // Assert
                Assert.IsNotNull(response);
                Assert.IsNull(result);
                Assert.AreEqual(response.Id, expectedResponse.Id);
            }
        }