Exemple #1
0
        public async Task Should_ThrowException_When_PassLeaveTypeIdDoesNotBelongsToCompanyId()
        {
            // Arrange
            var leaveType = new LeaveType()
            {
                LeaveTypeId   = 1,
                CompanyId     = 1,
                LeaveTypeName = "Leave Type Test",
                CreatedAt     = DateTime.Now,
                CreatedBy     = -1,
                IsDeleted     = true,
                IsActive      = false
            };

            IRepository <LeaveType> repository = new Repository <LeaveType>(_fixture.Context);

            var handler      = new GetLeaveTypeHandler(repository, _mapper, _logger);
            var queryRequest = new GetLeaveTypeQuery(leaveTypeId: 1, companyId: 2);

            _fixture.Context.LeaveTypes.Add(leaveType);
            _fixture.Context.SaveChanges();

            // Act
            var tcs = new CancellationToken();


            var exception = await Assert.ThrowsAsync <VacationTrackingException>(async() =>
            {
                await handler.Handle(queryRequest, tcs);
            });

            // Assert
            Assert.Equal(404, exception.Code);
            Assert.Equal(ExceptionMessages.ItemNotFound, exception.Message);
        }
Exemple #2
0
        public async Task Should_ReturnLeaveTypeObject_When_PassInactiveLeaveTypeId()
        {
            // Arrange
            var leaveType = new LeaveType()
            {
                LeaveTypeId   = 1,
                CompanyId     = 1,
                LeaveTypeName = "Leave Type Test",
                CreatedAt     = DateTime.Now,
                CreatedBy     = -1,
                IsDeleted     = false,
                IsActive      = false
            };

            IRepository <LeaveType> repository = new Repository <LeaveType>(_fixture.Context);

            var handler      = new GetLeaveTypeHandler(repository, _mapper, _logger);
            var queryRequest = new GetLeaveTypeQuery(leaveTypeId: 1, companyId: 1);

            _fixture.Context.LeaveTypes.Add(leaveType);
            _fixture.Context.SaveChanges();

            // Act
            var tcs = new CancellationToken();

            var result = await handler.Handle(queryRequest, tcs);

            // Assert
            Assert.Equal(1, result.LeaveTypeId);
            Assert.Equal(1, result.CompanyId);
        }
Exemple #3
0
        public async Task Should_ThrowException_When_PassInvalidLeaveTypeId()
        {
            // Arrange
            IRepository <LeaveType> repository = new Repository <LeaveType>(_fixture.Context);

            var handler      = new GetLeaveTypeHandler(repository, _mapper, _logger);
            var queryRequest = new GetLeaveTypeQuery(leaveTypeId: -1, companyId: 1);

            // Act
            var tcs = new CancellationToken();


            var exception = await Assert.ThrowsAsync <VacationTrackingException>(async() =>
            {
                await handler.Handle(queryRequest, tcs);
            });

            // Assert
            Assert.Equal(404, exception.Code);
            Assert.Equal(ExceptionMessages.ItemNotFound, exception.Message);
        }