コード例 #1
0
        public void PatchUser_ShouldHaveUniqueEmail()
        {
            var context = new TestRedCoreContext();

            context.user.Add(new user {
                userid = 1, name = "Demo1", email = "*****@*****.**", telephone = "0761670000", address = "testgatan 123", post_code = "11111", city = "Stockholm"
            });
            context.user.Add(new user {
                userid = 2, name = "Demo2", email = "*****@*****.**", telephone = "0761670000", address = "testgatan 123", post_code = "11111", city = "Stockholm"
            });
            var controller = new UsersController(context);

            var delta = new Delta <user>(typeof(user));

            delta.TrySetPropertyValue("name", "Demo1");
            delta.TrySetPropertyValue("email", "*****@*****.**");
            delta.TrySetPropertyValue("userid", 1);

            dynamic result     = controller.Patchuser(1, delta);
            dynamic content    = result.Content;
            dynamic statusCode = result.StatusCode;

            Assert.AreEqual(HttpStatusCode.Conflict, statusCode);
            Assert.AreEqual(content.message, "An existing record with the email was already found.");
        }
コード例 #2
0
        public void GetUser_ShouldReturnUserWithSameID()
        {
            var context = new TestRedCoreContext();

            context.user.Add(GetDemoUser());

            var controller = new UsersController(context);
            var result     = controller.Getuser(1) as OkNegotiatedContentResult <user>;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Content.userid);
        }
コード例 #3
0
        public void DeleteUser_ShouldReturnOK()
        {
            var context = new TestRedCoreContext();
            var item    = GetDemoUser();

            context.user.Add(item);
            var controller = new UsersController(context);
            var result     = controller.Deleteuser(1) as OkNegotiatedContentResult <user>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.userid, result.Content.userid);
        }
コード例 #4
0
        public void PostUser_ShouldHaveUniqueEmail()
        {
            var context = new TestRedCoreContext();

            context.user.Add(new user {
                userid = 2, name = "Demo2", email = "*****@*****.**", telephone = "0761670000", address = "testgatan 123", post_code = "11111", city = "Stockholm"
            });
            var     controller = new UsersController(context);
            var     item       = GetUserWithSameEmail();
            dynamic result     = controller.Postuser(item);
            dynamic content    = result.Content;
            dynamic statusCode = result.StatusCode;

            Assert.AreEqual(HttpStatusCode.Conflict, statusCode);
            Assert.AreEqual(content.message, "An existing record with the email was already found.");
        }
コード例 #5
0
        public void GetUsers_ShouldReturnAllUsers()
        {
            var context = new TestRedCoreContext();

            context.user.Add(new user {
                userid = 1, name = "Demo1", email = "*****@*****.**", telephone = "0761670000", address = "testgatan 123", post_code = "11111", city = "Stockholm"
            });
            context.user.Add(new user {
                userid = 2, name = "Demo2", email = "*****@*****.**", telephone = "0761670000", address = "testgatan 123", post_code = "11111", city = "Stockholm"
            });
            context.user.Add(new user {
                userid = 3, name = "Demo3", email = "*****@*****.**", telephone = "0761670000", address = "testgatan 123", post_code = "11111", city = "Stockholm"
            });

            var controller = new UsersController(context);
            var result     = controller.Getuser() as TestUserDbSet;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }
コード例 #6
0
        public void PatchUser_ShouldReturnStatusCode()
        {
            var context = new TestRedCoreContext();

            context.user.Add(new user {
                userid = 1, name = "Demo1", email = "*****@*****.**", telephone = "0761670000", address = "testgatan 123", post_code = "11111", city = "Stockholm"
            });
            var controller = new UsersController(context);


            var delta = new Delta <user>(typeof(user));

            delta.TrySetPropertyValue("name", "Demo2");
            delta.TrySetPropertyValue("userid", 1);

            var result = controller.Patchuser(1, delta) as StatusCodeResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }