Exemplo n.º 1
0
        public async Task GetPermissionAsync_WithTestGuid_ReturnsCorrectResult()
        {
            // Arrange
            var permissionService = Substitute.For <IPermissionService>();
            var testGuid          = Guid.NewGuid();
            var testName          = "TestUserName";

            permissionService.GetByIdAsync(testGuid).Returns(new Permission {
                Uuid = testGuid, Name = testName
            });

            var controller = new PermissionsController(permissionService);

            // Act
            IActionResult actionResult = await controller.GetPermissionAsync(testGuid);

            // Assert
            var okResult = actionResult as OkObjectResult;

            Assert.NotNull(okResult);

            var permission = okResult.Value as Permission;

            Assert.NotNull(permission);
            Assert.True(permission.Uuid == testGuid, $"Retrieved Id {permission.Uuid} not the same as sample id {testGuid}.");
            Assert.True(permission.Name == testName, $"Retrieved Name {permission.Name} not the same as sample id {testName}.");
        }
Exemplo n.º 2
0
        public async Task GetPermissionAsync_WithRandomGuid_ReturnsNotFoundResult()
        {
            // Arrange
            var permissionService = Substitute.For <IPermissionService>();
            var controller        = new PermissionsController(permissionService);

            // Act
            var result = await controller.GetPermissionAsync(Guid.NewGuid());

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
Exemplo n.º 3
0
        public async Task GetPermissionAsync_WithEmptyGuid_ReturnsBadRequest()
        {
            // Arrange
            var permissionService = Substitute.For <IPermissionService>();
            var controller        = new PermissionsController(permissionService);

            // Act
            var result = await controller.GetPermissionAsync(Guid.Empty);

            // Assert
            var badRequestResult = result as BadRequestResult;

            Assert.NotNull(badRequestResult);
        }