예제 #1
0
        public async Task DraftFileBusinessLogic_RollbackDraft_Maintains_Initial_Information_Added_In_One_SessionAsync()
        {
            // Arrange
            var kathyUserId          = testUserId;
            var systemFileRepository = new SystemFileRepository(new StorageOptions());

            testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, systemFileRepository);
            var returnViewModelThatKathyWillSendFirst = new ReturnViewModel {
                DiffMeanBonusPercent = 20.2m
            };
            var returnViewModelThatKathyWillSendSecond = new ReturnViewModel
            {
                DiffMeanBonusPercent = 30.3m, DiffMedianBonusPercent = 33.3m
            };
            var returnViewModelThatKathyWillSendThird = new ReturnViewModel
            {
                DiffMeanBonusPercent = 40.4m, DiffMedianBonusPercent = 44.4m,
                OrganisationSize     = OrganisationSizes.Employees250To499
            };

            // Act
            var emptyDraftLockedToKathy =
                await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear,
                                                                       kathyUserId);

            Assert.True(await systemFileRepository.GetFileExistsAsync(emptyDraftLockedToKathy.DraftPath));
            Assert.True(await systemFileRepository.GetFileExistsAsync(emptyDraftLockedToKathy.BackupDraftPath));

            var draftWithFirstLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatKathyWillSendFirst,
                emptyDraftLockedToKathy,
                kathyUserId); // send data

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

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

            var draftWithSecondLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatKathyWillSendSecond,
                draftWithFirstLoadOfData,
                kathyUserId); // send data

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

            Assert.AreEqual(30.3m, intermediateDraftInfo.ReturnViewModelContent.DiffMeanBonusPercent);
            Assert.AreEqual(33.3m, intermediateDraftInfo.ReturnViewModelContent.DiffMedianBonusPercent);
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithSecondLoadOfData.DraftPath));
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithSecondLoadOfData.BackupDraftPath));

            var draftWithThirdLoadOfData = await testDraftFileBusinessLogic.UpdateAsync(
                returnViewModelThatKathyWillSendThird,
                draftWithSecondLoadOfData,
                kathyUserId); // send data

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

            Assert.AreEqual(40.4m, intermediateDraftInfo.ReturnViewModelContent.DiffMeanBonusPercent);
            Assert.AreEqual(44.4m, intermediateDraftInfo.ReturnViewModelContent.DiffMedianBonusPercent);
            Assert.AreEqual(OrganisationSizes.Employees250To499,
                            intermediateDraftInfo.ReturnViewModelContent.OrganisationSize);
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithThirdLoadOfData.DraftPath));
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithThirdLoadOfData.BackupDraftPath));

            await testDraftFileBusinessLogic.RollbackDraftAsync(draftWithThirdLoadOfData);

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

            Assert.Null(intermediateDraftInfo.ReturnViewModelContent);
            Assert.True(await systemFileRepository.GetFileExistsAsync(draftWithFirstLoadOfData.BackupDraftPath));

            // Cleanup
            await testDraftFileBusinessLogic.DiscardDraftAsync(draftWithSecondLoadOfData);
        }
예제 #2
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);
        }