コード例 #1
0
        public void Should_Return_Log_When_Archive_With_Manager(int logId)
        {
            // Arrange
            var fakes              = new Fakes();
            var fakeHttp           = fakes.FakeHttpContextAccessor(true).Object;
            var fakeRepository     = fakes.FakeLogRepository().Object;
            var fakeUserRepository = fakes.FakeUserRepository().Object;
            var hashService        = new HashService();
            var userService        = new UserService(fakes.Mapper, fakeHttp, fakeUserRepository, hashService);

            var log = fakeRepository.GetById(logId).Result;

            log.Archived = !log.Archived; // Should change log archiving state
            var response = fakes.Mapper.Map <LogResponse>(log);
            var expected = Responses.OkResponse(null, response);

            // Act
            var service = new LogService(fakes.Mapper, fakeRepository, userService);
            var actual  = service.Archive(logId).Result;

            // Assert
            Assert.IsType <Response>(actual);
            Assert.NotNull(actual);
            Assert.Equal(expected, actual, new LogResponseComparer());
        }
コード例 #2
0
        public void Should_Return_BadRequest_When_Archive_And_Exception_Is_Thrown()
        {
            // Arrange
            var logId              = 1;
            var fakes              = new Fakes();
            var fakeHttp           = fakes.FakeHttpContextAccessor(true).Object;
            var fakeRepository     = fakes.FakeLogRepositoryException().Object;
            var fakeUserRepository = fakes.FakeUserRepository().Object;
            var hashService        = new HashService();
            var userService        = new UserService(fakes.Mapper, fakeHttp, fakeUserRepository, hashService);

            var expected = Responses.BadRequestResponse("Test Exception");

            // Act
            var service = new LogService(fakes.Mapper, fakeRepository, userService);
            var actual  = service.Archive(logId).Result;

            // Assert
            Assert.ThrowsAnyAsync <Exception>(() => service.Archive(logId));
            Assert.IsType <Response>(actual);
            Assert.NotNull(actual);
            Assert.Equal(expected, actual, new ResponseComparer());
        }
コード例 #3
0
        public void Should_Return_NotFound_When_Archive_With_An_Incorrect_Id()
        {
            // Arrange
            var logId              = 9999;
            var fakes              = new Fakes();
            var fakeHttp           = fakes.FakeHttpContextAccessor(true).Object;
            var fakeRepository     = fakes.FakeLogRepository().Object;
            var fakeUserRepository = fakes.FakeUserRepository().Object;
            var hashService        = new HashService();
            var userService        = new UserService(fakes.Mapper, fakeHttp, fakeUserRepository, hashService);

            var expected = Responses.NotFoundResponse("Log não encontrado");

            // Act
            var service = new LogService(fakes.Mapper, fakeRepository, userService);
            var actual  = service.Archive(logId).Result;

            // Assert
            Assert.IsType <Response>(actual);
            Assert.NotNull(actual);
            Assert.Equal(expected, actual, new ResponseComparer());
        }
コード例 #4
0
        public void Should_Return_Forbidden_When_Archive_Without_Authorization(int logId)
        {
            // Arrange
            var fakes              = new Fakes();
            var loggedUserId       = 0; // Doesn't exist user with id 0
            var fakeHttp           = fakes.FakeHttpContextAccessor(false, loggedUserId).Object;
            var fakeRepository     = fakes.FakeLogRepository().Object;
            var fakeUserRepository = fakes.FakeUserRepository().Object;
            var hashService        = new HashService();
            var userService        = new UserService(fakes.Mapper, fakeHttp, fakeUserRepository, hashService);

            var expected = Responses.ForbiddenResponse(
                "Não é possível arquivar ou desarquivar um log de outro usuário");

            // Act
            var service = new LogService(fakes.Mapper, fakeRepository, userService);
            var actual  = service.Archive(logId).Result;

            // Assert
            Assert.IsType <Response>(actual);
            Assert.NotNull(actual);
            Assert.Equal(expected, actual, new ResponseComparer());
        }