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); }
DraftFileBusinessLogic_GetDraftIfAvailable_When_Json_Has_Data_And_Bak_File_Empty_Return_NullAsync() { // Arrange var oliviaUserId = testUserId; var systemFileRepository = new SystemFileRepository(new StorageOptions()); testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, systemFileRepository); var returnViewModelThatOliviaWillSendFirst = new ReturnViewModel { DiffMedianBonusPercent = 11.1m }; var emptyDraftLockedToOlivia = await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear, oliviaUserId); await testDraftFileBusinessLogic.UpdateAsync(returnViewModelThatOliviaWillSendFirst, emptyDraftLockedToOlivia, oliviaUserId); // Act var availableDraft = await testDraftFileBusinessLogic.GetDraftIfAvailableAsync(testOrganisationId, testSnapshotYear); // Assert Assert.Null( availableDraft, "Both files exist, as it is an inconsistent state (bak shouldn't be there if the process completed correctly), we used the backed up file as the reference because it's the most 'correct'. Bak file was empty, therefore null was expected"); // Cleanup await testDraftFileBusinessLogic.DiscardDraftAsync(emptyDraftLockedToOlivia); }
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); }
public async Task DraftFileBusinessLogic_GetDraftIfAvailable_When_Not_Json_Return_NullAsync() { // Arrange testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, new SystemFileRepository(new StorageOptions())); // Act var availableDraft = await testDraftFileBusinessLogic.GetDraftIfAvailableAsync(testOrganisationId, testSnapshotYear); // Assert Assert.Null(availableDraft, "Json isn't available, so it is expected that 'available draft' is null"); }
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); }
DraftFileBusinessLogic_GetDraftIfAvailable_When_Json_Empty_And_Bak_File_Empty_Return_NullAsync() { // Arrange var robertUserId = testUserId; var systemFileRepository = new SystemFileRepository(new StorageOptions()); testDraftFileBusinessLogic = new DraftFileBusinessLogic(null, systemFileRepository); var emptyDraftLockedToRobert = await testDraftFileBusinessLogic.GetExistingOrNewAsync(testOrganisationId, testSnapshotYear, robertUserId); // Act var availableDraft = await testDraftFileBusinessLogic.GetDraftIfAvailableAsync(testOrganisationId, testSnapshotYear); // Assert Assert.Null(availableDraft, "Both files exist but both empty, so no draft"); // Cleanup await testDraftFileBusinessLogic.DiscardDraftAsync(emptyDraftLockedToRobert); }