public async Task GetAssetsByEmployeeId_WithEmployeeWithAssets_ShouldReturnCorrectResult(string employeeId)
        {
            string errorMessagePrefix = "AssetsService GetAssetsByEmployeeId() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assetsService = new AssetsService(context);

            List <AssetEmployeeDto> actualResults = await this.assetsService.GetAssetsByEmployeeId(employeeId).ToListAsync();

            List <AssetEmployeeDto> expectedResults = GetDummyData().Where(a => a.Employee != null && a.Employee.Id == employeeId).To <AssetEmployeeDto>().ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.InventoryNumber == actualEntry.InventoryNumber, errorMessagePrefix + " " + "InventoryNumber is not returned properly.");
                Assert.True(expectedEntry.Make == actualEntry.Make, errorMessagePrefix + " " + "Make is not returned properly.");
                Assert.True(expectedEntry.Model == actualEntry.Model, errorMessagePrefix + " " + "Model is not returned properly.");
                Assert.True(expectedEntry.DateOfAquire == actualEntry.DateOfAquire, errorMessagePrefix + " " + "DateOfAquire is not returned properly.");
                Assert.True(expectedEntry.ReferenceNumber == actualEntry.ReferenceNumber, errorMessagePrefix + " " + "ReferenceNumber is not returned properly.");
                Assert.True(expectedEntry.AssetTypeName == actualEntry.AssetTypeName, errorMessagePrefix + " " + "AssetTypeName is not returned properly.");
            }
            Assert.True(expectedResults.Count == actualResults.Count, errorMessagePrefix + " " + "Count of returned assets is not correct");
        }
        public async Task CreateAsync_WithValidData_ShouldCreateAssetAndReturnTrue()
        {
            string errorMessagePrefix = "AssetsService CreateAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assetsService = new AssetsService(context);

            var assetToCreate = new AssetCreateDto
            {
                InventoryNumber = "190828-OLC-Asset5",
                Make            = "Microsoft",
                Model           = "Windows 10 Professional",
                ReferenceNumber = "OLC-01-09-SC",
                DateOfAquire    = "27-08-2019",
                AssetTypeId     = 1,
                EmployeeId      = "02",
            };

            bool actualResult = await this.assetsService.CreateAsync(assetToCreate);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task EditAsync_WithInvalidAssetId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assetsService = new AssetsService(context);

            string invalidAssetId = "InvalidId";

            AssetEditDto expectedResult = (await context.Assets.FirstAsync()).To <AssetEditDto>();

            expectedResult.ReferenceNumber = "New Ref Number";
            expectedResult.Make            = "New make";
            expectedResult.Model           = "New model";
            expectedResult.InventoryNumber = "190828-OLC-Changed Number";
            expectedResult.DateOfAquire    = "29-08-2019";
            expectedResult.EmployeeId      = "02";
            expectedResult.AssetTypeId     = 3;
            expectedResult.Id = invalidAssetId;

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.assetsService.EditAsync(expectedResult));

            Assert.Equal(string.Format(ErrorMessages.AssetIdNullReference, expectedResult.Id), ex.Message);
        }
        public async Task AddParticipantsAsync_WithValidData_ShouldAddProjectParticipantsAndReturnTrue()
        {
            string errorMessagePrefix = "EmployeesProjectsPositions AddParticipantsAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            List <EmployeesProjectsPositions> newEntities = new List <EmployeesProjectsPositions>
            {
                new EmployeesProjectsPositions {
                    EmployeeId = Employee_Id_4, ProjectId = Project_Id_1, ProjectPositionId = ProjectPosition_Id_2
                },
                new EmployeesProjectsPositions {
                    EmployeeId = Employee_Id_5, ProjectId = Project_Id_1, ProjectPositionId = ProjectPosition_Id_3
                },
            };

            List <ProjectEditParticipantDto> entitiesToAdd = newEntities.To <ProjectEditParticipantDto>().ToList();

            var expectedCount = context.EmployeesProjectsRoles.Count() + entitiesToAdd.Count;

            bool result = await this.employeesProjectsPositionsService.AddParticipantsAsync(entitiesToAdd);

            var actualCount = context.EmployeesProjectsRoles.Count();

            Assert.True(result, errorMessagePrefix);
            Assert.True(expectedCount == actualCount, errorMessagePrefix);
        }
        public async Task GetActivitiesByReportId_WithValidData_ShouldReturnCorrectResult(string reportId)
        {
            string errorMessagePrefix = "ActivitiesService CreateActivityAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.activitiesService = new ActivitiesService(context);

            List <ActivityPieDataDto> actualResults = await this.activitiesService.GetActivitiesByReportId(reportId).ToListAsync();

            List <ActivityPieDataDto> expectedResults = GetDummyData().Where(a => a.ReportId == reportId).To <ActivityPieDataDto>().ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.WorkingMinutes == actualEntry.WorkingMinutes, errorMessagePrefix + " " + "WorkingMinutes is not returned properly.");
                Assert.True(expectedEntry.EmployeeId == actualEntry.EmployeeId, errorMessagePrefix + " " + "EmployeeId is not returned properly.");
                Assert.True(expectedEntry.EmployeeFullName == actualEntry.EmployeeFullName, errorMessagePrefix + " " + "EmployeeFullName is not returned properly.");
            }
            Assert.True(expectedResults.Count == actualResults.Count, errorMessagePrefix + " " + "Count of returned activities is not correct");
        }
        public async Task CreateWithAssistantsIds_WithValidData_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "AssignmentEmployeesService CreateWithAssistantsIds() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assignmentsEmployeesService = new AssignmentsEmployeesService(context);

            List <string> employeesIdsToCreateAssignmentWith = new List <string> {
                Employee_Id_3, Employee_Id_4
            };

            var expectedCount = employeesIdsToCreateAssignmentWith.Count;

            List <AssignmentsEmployees> actualResult = this.assignmentsEmployeesService.CreateWithAssistantsIds(employeesIdsToCreateAssignmentWith).ToList();

            var actualCount = actualResult.Count;

            for (int i = 0; i < expectedCount; i++)
            {
                Assert.True(employeesIdsToCreateAssignmentWith[i] == actualResult[i].AssistantId, errorMessagePrefix + " " + "Assistant not created correctly!");
            }
            Assert.True(expectedCount == actualCount, errorMessagePrefix + " " + "Assistants were not added correctly!");
        }
        public async Task EditAsync_WithCorrectData_ShouldEditAssetCorrectly()
        {
            string errorMessagePrefix = "AssetsService EditAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assetsService = new AssetsService(context);

            AssetEditDto expectedResult = (await context.Assets.FirstAsync()).To <AssetEditDto>();

            expectedResult.ReferenceNumber = "New Ref Number";
            expectedResult.Make            = "New make";
            expectedResult.Model           = "New model";
            expectedResult.InventoryNumber = "190828-OLC-Changed Number";
            expectedResult.DateOfAquire    = "29-08-2019";
            expectedResult.EmployeeId      = "02";
            expectedResult.AssetTypeId     = 3;

            await this.assetsService.EditAsync(expectedResult);

            var actualResult = (await context.Assets.FirstAsync()).To <AssetEditDto>();

            Assert.True(expectedResult.InventoryNumber == actualResult.InventoryNumber, errorMessagePrefix + " " + "InventoryNumber is not changed properly.");
            Assert.True(expectedResult.Make == actualResult.Make, errorMessagePrefix + " " + "Make is not changed properly.");
            Assert.True(expectedResult.Model == actualResult.Model, errorMessagePrefix + " " + "Model is not changed properly.");
            Assert.True(expectedResult.ReferenceNumber == actualResult.ReferenceNumber, errorMessagePrefix + " " + "ReferenceNumber is not changed properly.");
            Assert.True(expectedResult.DateOfAquire == actualResult.DateOfAquire, errorMessagePrefix + " " + "DateOfAquire is not changed properly.");
            Assert.True(expectedResult.EmployeeId == actualResult.EmployeeId, errorMessagePrefix + " " + "EmployeeId is not changed properly.");
            Assert.True(expectedResult.AssetTypeId == actualResult.AssetTypeId, errorMessagePrefix + " " + "AssetTypeId is not changed properly.");
        }
Esempio n. 8
0
        public async Task GetLeavingReasons_WithZeroData_ShouldReturnEmptyResults()
        {
            string errorMessagePrefix = "LeavingReasons GetLeavingReasons() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            this.leavingReasonsService = new LeavingReasonsService(context);

            List <LeavingReasonDto> actualResults = await this.leavingReasonsService.GetLeavingReasons().ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix + " " + "Count of returned leaving reasons is not correct");
        }
Esempio n. 9
0
        public async Task GetDepartmentNameByIdAsync_WithInvalidId_ShouldThrowArgumentOutOfRangeException(int id)
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.departmentsService = new DepartmentsService(context);

            var ex = await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => this.departmentsService.GetDepartmentNameByIdAsync(id));

            Assert.Equal(string.Format(ErrorMessages.DepartmentInvalidRange, id), ex.Message);
        }
Esempio n. 10
0
        public async Task CreateReportAsync_WithExistingProjectIdInReports_ShouldThrowArgumentException(string projectId)
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.reportsService = new ReportsService(context);

            var ex = await Assert.ThrowsAsync <ArgumentException>(() => this.reportsService.CreateReportAsync(projectId));

            Assert.Equal(string.Format(ErrorMessages.ReportInvalidProjectId, projectId), ex.Message);
        }
Esempio n. 11
0
        public async Task GetStatusIdByNameAsync_WithNullName_ShouldThrowArgumentNullException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.statusesService = new StatusesService(context);

            var ex = await Assert.ThrowsAsync <ArgumentNullException>(() => this.statusesService.GetStatusIdByNameAsync(null));

            Assert.Equal(ErrorMessages.StatusNullParameter, ex.Message);
        }
Esempio n. 12
0
        public async Task GetAll_WithZeroData_ShouldReturnEmptyResults()
        {
            string errorMessagePrefix = "StatusesService GetAllStatuses() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            this.statusesService = new StatusesService(context);

            List <StatusListDto> actualResults = await this.statusesService.GetAllStatuses().ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix + " " + "Count of returned statuses is not correct");
        }
Esempio n. 13
0
        public async Task GetStatusIdByNameAsync_WithInvalidName_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.statusesService = new StatusesService(context);

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.statusesService.GetStatusIdByNameAsync(Invalid_Status_Name));

            Assert.Equal(string.Format(ErrorMessages.StatusNameNullReference, Invalid_Status_Name), ex.Message);
        }
Esempio n. 14
0
        public async Task GetAllDepartmentsByDto_WithZeroData_ShouldReturnEmptyResults()
        {
            string errorMessagePrefix = "Departments GetAllDepartmentsByDto() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            this.departmentsService = new DepartmentsService(context);

            List <DepartmentListDto> actualResults = await this.departmentsService.GetAllDepartmentsByDto <DepartmentListDto>().ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix + " " + "Count of returned departments is not correct");
        }
        public async Task GetActivitiesByReportId_WithZeroData_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "ActivitiesService CreateActivityAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.activitiesService = new ActivitiesService(context);

            List <ActivityPieDataDto> actualResults = await this.activitiesService.GetActivitiesByReportId(null).ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix + " " + "Count of returned activities is not correct");
        }
        public async Task DeleteActivityAsync_WithInvalidId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.activitiesService = new ActivitiesService(context);

            string invalidId = "Invalid Id";

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.activitiesService.DeleteActivityAsync(invalidId));

            Assert.Equal(string.Format(ErrorMessages.ActivityIdNullReference, invalidId), ex.Message);
        }
Esempio n. 17
0
        public async Task GetReportById_WithInvalidId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.reportsService = new ReportsService(context);

            string invalidId = "Invalid id";

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.reportsService.GetReportById <ReportDetailsDto>(invalidId).SingleAsync());

            Assert.Equal(string.Format(ErrorMessages.ReportIdNullReference, invalidId), ex.Message);
        }
Esempio n. 18
0
        public async Task DeleteAsync_WithValidId_ShouldDeleteCommentAndReturnTrue(string commentId)
        {
            string errorMessagePrefix = "CommentsService DeleteAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.commentsService = new CommentsService(context);

            bool actualResult = await this.commentsService.DeleteAsync(commentId);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task GetAssetsByEmployeeId_WithEmployeeWithoutAssets_ShouldReturnEmptyColleciton()
        {
            string errorMessagePrefix = "AssetsService GetAssetsByEmployeeId() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assetsService = new AssetsService(context);

            List <AssetEmployeeDto> actualResults = await this.assetsService.GetAssetsByEmployeeId("Invalid").ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix + " " + "Count of returned assets is not correct");
        }
Esempio n. 20
0
        public async Task CreateReportAsync_WithInvalidProjectId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.reportsService = new ReportsService(context);

            string invalidId = "Invalid id";

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.reportsService.CreateReportAsync(invalidId));

            Assert.Equal(string.Format(ErrorMessages.ProjectIdNullReference, invalidId), ex.Message);
        }
Esempio n. 21
0
        public async Task GetDepartmentNameByIdAsync_ShouldReturnCorrectResult(string expectedName, int departmentId)
        {
            string errorMessagePrefix = "ProjectPositions GetProjectPositionNameByIdAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.departmentsService = new DepartmentsService(context);

            var actualName = await this.departmentsService.GetDepartmentNameByIdAsync(departmentId);

            Assert.True(expectedName == actualName, errorMessagePrefix + " " + "The project position name is not correct");
        }
Esempio n. 22
0
        public async Task GetStatusNameByIdAsync_ShouldReturnCorrectResult(string expectedName, int statusId)
        {
            string errorMessagePrefix = "StatusesService GetStatusIdByNameAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.statusesService = new StatusesService(context);

            var actualName = await this.statusesService.GetStatusNameByIdAsync(statusId);

            Assert.True(expectedName == actualName, errorMessagePrefix + " " + "The status name is not correct");
        }
Esempio n. 23
0
        public async Task CreateReportAsync_WithValidData_ShouldCreateReportAndReturnTrue(string projectId)
        {
            string errorMessagePrefix = "ReportsService CreateReportAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedProjectData(context);

            this.reportsService = new ReportsService(context);

            bool actualResult = await this.reportsService.CreateReportAsync(projectId);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task RemoveParticipantAsync_WithInvalidProjectId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            ProjectParticipantChangeDto entityToRemove = (await context.EmployeesProjectsRoles.FirstAsync()).To <ProjectParticipantChangeDto>();

            entityToRemove.ProjectId = "Invalid id";

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.employeesProjectsPositionsService.RemoveParticipantAsync(entityToRemove));

            Assert.Equal(ErrorMessages.ProjectParticipantNullReference, ex.Message);
        }
        public async Task RemoveParticipantsAsync_WithEmptyData_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            string invalidId = "Invalid id";

            List <ProjectEditParticipantDto> entitiesToRemove = GetEmployeeProjectsPositionsDummyData().Where(epp => epp.ProjectId == invalidId).To <ProjectEditParticipantDto>().ToList();

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.employeesProjectsPositionsService.RemoveParticipantsAsync(entitiesToRemove));

            Assert.Equal(ErrorMessages.ProjectParticipantsToRemoveNullReference, ex.Message);
        }
        public async Task AddAssistantsAsync_WithExistendAssistantId_ShouldThowArgumentException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assignmentsEmployeesService = new AssignmentsEmployeesService(context);

            List <string> employeesIdsToAddToAssignment = new List <string> {
                Employee_Id_3, Employee_Id_1
            };

            var ex = await Assert.ThrowsAsync <ArgumentException>(() => this.assignmentsEmployeesService.AddAssistantsAsync(employeesIdsToAddToAssignment, Assignment_Id_1));

            Assert.Equal(ErrorMessages.AssistantArgumentException, ex.Message);
        }
        public async Task DeleteAsync_WithValidId_ShouldDeleteAssetAndReturnTrue()
        {
            string errorMessagePrefix = "AssetsService DeleteAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assetsService = new AssetsService(context);

            var assetToDeleteId = (await context.Assets.FirstAsync()).Id;

            bool actualResult = await this.assetsService.DeleteAsync(assetToDeleteId);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task ChangeEmployeeProjectPositionAsync_WithInvalidProjectPositionId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            ProjectParticipantChangeDto expectedResult = GetEmployeeProjectsPositionsDummyData().First().To <ProjectParticipantChangeDto>();
            int invalidProjectPositionId = 22;

            expectedResult.ProjectPositionId = invalidProjectPositionId;

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.employeesProjectsPositionsService.ChangeEmployeeProjectPositionAsync(expectedResult));

            Assert.Equal(string.Format(ErrorMessages.ProjectPositionNullReference, invalidProjectPositionId), ex.Message);
        }
        public async Task DeleteActivityAsync_WithValidData_ShouldDeleteActivityAndReturnTrue(string id)
        {
            string errorMessagePrefix = "ActivitiesService DeleteActivityAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.activitiesService = new ActivitiesService(context);

            bool actualResult = await this.activitiesService.DeleteActivityAsync(id);

            var actualActivitiesCount = context.Activities.Count();

            Assert.True(actualResult, errorMessagePrefix);
            Assert.True(actualActivitiesCount == 1, errorMessagePrefix);
        }
Esempio n. 30
0
        public async Task GetReportById_WithValidData_ShouldReturnCorrectResult(string id)
        {
            string errorMessagePrefix = "ActivitiesService EditActivityAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.reportsService = new ReportsService(context);

            ReportDetailsDto expectedResult = (await context.Reports.SingleAsync(a => a.Id == id)).To <ReportDetailsDto>();
            ReportDetailsDto actualResult   = await this.reportsService.GetReportById <ReportDetailsDto>(id).SingleAsync();

            Assert.True(expectedResult.Project.Id == actualResult.Project.Id, errorMessagePrefix + " " + "Project id is not returned properly.");
            Assert.True(expectedResult.Project.Name == actualResult.Project.Name, errorMessagePrefix + " " + "Project name is not returned properly.");
            Assert.True(expectedResult.Activities.Count == actualResult.Activities.Count, errorMessagePrefix + " " + "Acivities are not returned properly.");
        }