Beispiel #1
0
        public async Task Post_ValidModel_ReturnsCreatedAtRouteResult()
        {
            string roleName        = "admin";
            string roleDescription = "admin role desc";

            RolePostRequest model = new RolePostRequest {
                Name = roleName, Description = roleDescription
            };

            this.roleManagerMock.Setup(r => r.CreateAsync(It.IsAny <ApplicationRole>())).ReturnsAsync(IdentityResult.Success);

            var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object);

            controller.BindViewModel(model);

            var response = await controller.Post(model).ConfigureAwait(false);

            Assert.IsAssignableFrom <CreatedAtRouteResult>(response);

            CreatedAtRouteResult result = response as CreatedAtRouteResult;

            Assert.Equal("RoleGet", result.RouteName);
            Assert.True(result.RouteValues.Keys.Contains("roleName"));
            Assert.True(result.RouteValues.Values.Contains("admin"));
            Assert.Equal(result.Value, model);
        }
Beispiel #2
0
        public async Task Patch_ValidModel_ReturnsOkResult()
        {
            string roleName        = "admin";
            string roleDescription = "admin role desc";

            RolePatchRequest model = new RolePatchRequest {
                Description = roleDescription
            };

            this.roleManagerMock.Setup(r => r.FindByNameAsync("admin")).ReturnsAsync(new ApplicationRole());
            this.roleManagerMock.Setup(r => r.UpdateAsync(It.IsAny <ApplicationRole>())).ReturnsAsync(IdentityResult.Success);

            var controller = new RoleController(this.roleManagerMock.Object, this.userManagerMock.Object, this.localizationMock.Object, this.mapperMock.Object);

            controller.BindViewModel(model);

            var response = await controller.Patch(roleName, model).ConfigureAwait(false);

            Assert.IsAssignableFrom <OkObjectResult>(response);
        }