Пример #1
0
        DraftFileBusinessLogic_GetDraftIfAvailable_When_Json_Has_Data_And_Not_Bak_File_Return_DraftAsync()
        {
            // Arrange
            var trevorUserId         = testUserId;
            var systemFileRepository = new SystemFileRepository(new StorageOptions());

            testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, systemFileRepository);
            var returnViewModelThatTrevorWillSendFirst = new ReturnViewModel {
                DiffMedianBonusPercent = 11.1m
            };

            var emptyDraftLockedToTrevor =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       trevorUserId);

            var draftWithFirstLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatTrevorWillSendFirst,
                emptyDraftLockedToTrevor,
                trevorUserId);

            await testDraftFileBusinessLogic.CommitDraftAsync(draftWithFirstLoadOfData);

            // Act
            var availableDraft =
                await testDraftFileBusinessLogic.GetDraftIfAvailableAsync(testOrganisationId, testSnapshotYear);

            // Assert
            Assert.NotNull(availableDraft,
                           "Json has data and there isn't a bak file, this is a consistent state, so a draft is available");

            // Cleanup
            await testDraftFileBusinessLogic.DiscardDraftAsync(availableDraft);
        }
Пример #2
0
        public async Task DraftFileBusinessLogic_GetDraftIfAvailable_When_Json_Empty_And_Not_Bak_File_Return_NullAsync()
        {
            // Arrange
            var clareUserId          = testUserId;
            var systemFileRepository = new SystemFileRepository(new StorageOptions());

            testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, systemFileRepository);

            var emptyDraftLockedToClare =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       clareUserId);

            await testDraftFileBusinessLogic.CommitDraftAsync(emptyDraftLockedToClare);

            // Act
            var availableDraft =
                await testDraftFileBusinessLogic.GetDraftIfAvailableAsync(testOrganisationId, testSnapshotYear);

            // Assert
            Assert.Null(
                availableDraft,
                "Json is empty (+ there isn't a bak file) as there isn't data to report, draft shouldn't be available");

            // Cleanup
            await testDraftFileBusinessLogic.DiscardDraftAsync(emptyDraftLockedToClare);
        }
Пример #3
0
        DraftFileBusinessLogic_GetDraftIfAvailable_When_Json_Has_Data_And_Bak_File_Has_Data_Return_Bak_Draft_InfoAsync()
        {
            // Arrange
            var joeUserId            = testUserId;
            var systemFileRepository = new SystemFileRepository(new StorageOptions());

            testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, systemFileRepository);
            var returnViewModelThatJoeWillSendFirst = new ReturnViewModel {
                DiffMedianBonusPercent = 11.1m
            };
            var returnViewModelThatJoeWillSendSecond =
                new ReturnViewModel {
                DiffMedianBonusPercent = 22.02m, DiffMeanHourlyPayPercent = 20.2m
            };

            var emptyDraftLockedToJoe =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear, joeUserId);

            var draftWithFirstLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatJoeWillSendFirst,
                emptyDraftLockedToJoe,
                joeUserId);

            await testDraftFileBusinessLogic.CommitDraftAsync(draftWithFirstLoadOfData);

            emptyDraftLockedToJoe =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear, joeUserId);

            draftWithFirstLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatJoeWillSendSecond,
                emptyDraftLockedToJoe,
                joeUserId);

            // Act
            var availableDraft =
                await testDraftFileBusinessLogic.GetDraftIfAvailableAsync(testOrganisationId, testSnapshotYear);

            // Assert
            Assert.NotNull(
                availableDraft,
                "Both files contain data, as it is an inconsistent state (bak shouldn't be there if the process completed correctly), we used the backed up data as it is the file we consider the most 'correct'");
            Assert.AreEqual(
                11.1m,
                availableDraft.ReturnViewModelContent.DiffMedianBonusPercent,
                "Information in the draft should be the one from the bak file");

            // Cleanup
            await testDraftFileBusinessLogic.DiscardDraftAsync(availableDraft);
        }
Пример #4
0
        public async Task DraftFileBusinessLogic_RestartDraft_Only_Json_Ignored_Nothing_To_Rollback_FromAsync()
        {
            // Arrange
            var anneUserId     = testUserId;
            var fileRepository = new SystemFileRepository(new StorageOptions());

            testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, fileRepository);
            var emptyDraftLockedToAnne =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       anneUserId);

            await testDraftFileBusinessLogic.CommitDraftAsync(emptyDraftLockedToAnne);

            // Act
            await testDraftFileBusinessLogic.RestartDraftAsync(testOrganisationId, testSnapshotYear, anneUserId);

            // Assert
            Assert.False(await fileRepository.GetFileExistsAsync(emptyDraftLockedToAnne.BackupDraftPath));

            // Cleanup
            await testDraftFileBusinessLogic.DiscardDraftAsync(emptyDraftLockedToAnne);
        }
Пример #5
0
        DraftFileBusinessLogic_CommitDraft_And_Then_RollbackDraft_Leaves_The_File_In_A_Consistent_StateAsync()
        {
            // Arrange
            var nicolasUserId        = testUserId;
            var systemFileRepository = new SystemFileRepository(new StorageOptions());

            testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, systemFileRepository);
            var returnViewModelThatNicolasWillSendFirst = new ReturnViewModel {
                DiffMeanBonusPercent = 10.1m
            };
            var returnViewModelThatNicolasWillSendSecond =
                new ReturnViewModel {
                DiffMeanBonusPercent = 20.2m, DiffMedianBonusPercent = 22.2m
            };
            var returnViewModelThatNicolasWillSendThird = new ReturnViewModel
            {
                DiffMeanBonusPercent = 30.3m, DiffMedianBonusPercent = 33.3m,
                OrganisationSize     = OrganisationSizes.Employees250To499
            };
            var returnViewModelThatNicolasWillSendFourth = new ReturnViewModel
            {
                DiffMeanBonusPercent = 40.4m, DiffMedianBonusPercent = 44.4m,
                OrganisationSize     = OrganisationSizes.Employees1000To4999
            };

            // Act
            var emptyDraftLockedToNicolas =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       nicolasUserId);

            Assert.False(emptyDraftLockedToNicolas.HasDraftBeenModifiedDuringThisSession);

            var draftWithFirstLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatNicolasWillSendFirst,
                emptyDraftLockedToNicolas,
                nicolasUserId); // send data

            Assert.False(draftWithFirstLoadOfData.HasDraftBeenModifiedDuringThisSession,
                         "this flag is set up by the front end");

            #region Confirm file status

            var intermediateDraftInfo =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       nicolasUserId);

            Assert.AreEqual(10.1m, intermediateDraftInfo.ReturnViewModelContent.DiffMeanBonusPercent);
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithFirstLoadOfData.DraftPath));
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithFirstLoadOfData.BackupDraftPath));

            #endregion

            var draftWithSecondLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatNicolasWillSendSecond,
                draftWithFirstLoadOfData,
                nicolasUserId); // send data

            Assert.False(
                draftWithSecondLoadOfData.HasDraftBeenModifiedDuringThisSession,
                "IsDraftDirty flag is set exclusively by the front end, so it always be 'false' unless the front end decides to change it.");

            #region Confirm file status

            intermediateDraftInfo =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       nicolasUserId);

            Assert.AreEqual(20.2m, intermediateDraftInfo.ReturnViewModelContent.DiffMeanBonusPercent);
            Assert.AreEqual(22.2m, intermediateDraftInfo.ReturnViewModelContent.DiffMedianBonusPercent);
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithFirstLoadOfData.DraftPath));
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithFirstLoadOfData.BackupDraftPath));

            #endregion

            await testDraftFileBusinessLogic.CommitDraftAsync(draftWithSecondLoadOfData);

            Assert.False(await systemFileRepository.GetFileExistsAsync(draftWithSecondLoadOfData.BackupDraftPath));

            var draftWithThirdLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatNicolasWillSendThird,
                draftWithSecondLoadOfData,
                nicolasUserId); // send data

            Assert.False(
                draftWithThirdLoadOfData.HasDraftBeenModifiedDuringThisSession,
                "IsDraftDirty flag is set exclusively by the front end, so it always be 'false' unless the front end decides to change it.");

            #region Confirm file status

            intermediateDraftInfo =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       nicolasUserId);

            Assert.AreEqual(30.3m, intermediateDraftInfo.ReturnViewModelContent.DiffMeanBonusPercent);
            Assert.AreEqual(33.3m, intermediateDraftInfo.ReturnViewModelContent.DiffMedianBonusPercent);
            Assert.AreEqual(OrganisationSizes.Employees250To499,
                            intermediateDraftInfo.ReturnViewModelContent.OrganisationSize);

            #endregion

            var draftWithFourthLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatNicolasWillSendFourth,
                draftWithThirdLoadOfData,
                nicolasUserId); // send data

            Assert.False(
                draftWithFourthLoadOfData.HasDraftBeenModifiedDuringThisSession,
                "IsDraftDirty flag is set exclusively by the front end, so it always be 'false' unless the front end decides to change it.");

            #region Confirm file status

            intermediateDraftInfo =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       nicolasUserId);

            Assert.AreEqual(40.4m, intermediateDraftInfo.ReturnViewModelContent.DiffMeanBonusPercent);
            Assert.AreEqual(44.4m, intermediateDraftInfo.ReturnViewModelContent.DiffMedianBonusPercent);
            Assert.AreEqual(OrganisationSizes.Employees1000To4999,
                            intermediateDraftInfo.ReturnViewModelContent.OrganisationSize);

            #endregion

            await testDraftFileBusinessLogic.RollbackDraftAsync(draftWithFourthLoadOfData);

            #region Confirm file status

            intermediateDraftInfo =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       nicolasUserId);

            Assert.AreEqual(20.2m, intermediateDraftInfo.ReturnViewModelContent.DiffMeanBonusPercent);
            Assert.AreEqual(22.2m, intermediateDraftInfo.ReturnViewModelContent.DiffMedianBonusPercent);
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithFirstLoadOfData.BackupDraftPath));
            Assert.False(
                intermediateDraftInfo.HasDraftBeenModifiedDuringThisSession,
                "IsDraftDirty flag is set exclusively by the front end, so it always be 'false' unless the front end decides to change it.");

            #endregion

            // Cleanup
            await testDraftFileBusinessLogic.DiscardDraftAsync(draftWithSecondLoadOfData);
        }