- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1
 
Heedls 925 temp data to database fix #1185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            13 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c5c8823
              
                HEEDLS-925 Add migration to create MultiPageFormData table
              
              
                AlexJacksonDS 1c6415f
              
                HEEDLS-925 Add new services and use them for AddNewCentreCourse journey
              
              
                AlexJacksonDS 3f12949
              
                Merge branch 'master' into HEEDLS-925-temp-data-to-database-fix
              
              
                AlexJacksonDS 8226aa4
              
                HEEDLS-925 Use new form data for Add Registration Prompt
              
              
                AlexJacksonDS d049fda
              
                HEEDLS-925 Change Edit registration prompt to form data
              
              
                AlexJacksonDS b69d4bb
              
                HEEDLS-925 Change Admin Field journeys to form data
              
              
                AlexJacksonDS 28cf100
              
                HEEDLS-925 Review markups
              
              
                AlexJacksonDS 9b6bbe2
              
                HEEDLS-925 Add index to MultipageFormData table
              
              
                AlexJacksonDS 6c22d8c
              
                HEEDLS-925 Rename data classes to TempData
              
              
                AlexJacksonDS b51a869
              
                HEEDLS-925 Review markups
              
              
                AlexJacksonDS 5ad11e4
              
                HEEDLS-925 Move model to data mappings to extensions
              
              
                AlexJacksonDS 9197892
              
                HEEDLS-925 Convert RedirectMissingMultiPageFormData to TypeFilter
              
              
                AlexJacksonDS 1724cad
              
                Merge branch 'master' into HEEDLS-925-temp-data-to-database-fix
              
              
                AlexJacksonDS File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            26 changes: 26 additions & 0 deletions
          
          26 
        
  DigitalLearningSolutions.Data.Migrations/202206131339_AddMultipageFormDataTable.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| namespace DigitalLearningSolutions.Data.Migrations | ||
| { | ||
| using FluentMigrator; | ||
| 
     | 
||
| [Migration(202206131339)] | ||
| public class AddMultiPageFormDataTable : Migration | ||
| { | ||
| public override void Up() | ||
| { | ||
| Create.Table("MultiPageFormData") | ||
| .WithColumn("ID").AsInt32().NotNullable().PrimaryKey().Identity() | ||
| .WithColumn("TempDataGuid").AsGuid().NotNullable() | ||
| .WithColumn("Json").AsCustom("NVARCHAR(MAX)").NotNullable() | ||
| .WithColumn("Feature").AsString(100).NotNullable() | ||
| .WithColumn("CreatedDate").AsDateTime().NotNullable(); | ||
| 
     | 
||
| Create.Index("IX_MultiPageFormData_TempDataGuid_Feature").OnTable("MultiPageFormData") | ||
| .OnColumn("TempDataGuid").Unique().OnColumn("Feature").Unique().WithOptions().Unique(); | ||
| } | ||
| 
     | 
||
| public override void Down() | ||
| { | ||
| Delete.Table("MultiPageFormData"); | ||
| } | ||
| } | ||
| } | ||
        
          
          
            200 changes: 200 additions & 0 deletions
          
          200 
        
  DigitalLearningSolutions.Data.Tests/DataServices/MultiPageFormDataServiceTests.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| namespace DigitalLearningSolutions.Data.Tests.DataServices | ||
| { | ||
| using System; | ||
| using System.Transactions; | ||
| using Dapper; | ||
| using DigitalLearningSolutions.Data.DataServices; | ||
| using DigitalLearningSolutions.Data.Enums; | ||
| using DigitalLearningSolutions.Data.Models.MultiPageFormData; | ||
| using DigitalLearningSolutions.Data.Tests.TestHelpers; | ||
| using FizzWare.NBuilder; | ||
| using FluentAssertions; | ||
| using Microsoft.Data.SqlClient; | ||
| using NUnit.Framework; | ||
| 
     | 
||
| public class MultiPageFormDataServiceTests | ||
| { | ||
| private readonly MultiPageFormData dataInDb = new MultiPageFormData | ||
| { | ||
| Id = 2, | ||
| TempDataGuid = Guid.NewGuid(), | ||
| Json = "test json", | ||
| Feature = MultiPageFormDataFeature.AddNewCourse.Name, | ||
| CreatedDate = new DateTime(2022, 06, 14, 14, 20, 12), | ||
| }; | ||
| 
     | 
||
| private SqlConnection connection = null!; | ||
| 
     | 
||
| private IMultiPageFormDataService multiPageFormDataService = null!; | ||
| 
     | 
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| connection = ServiceTestHelper.GetDatabaseConnection(); | ||
| multiPageFormDataService = new MultiPageFormDataService(connection); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void GetMultiPageFormDataByGuidAndFeature_returns_expected_MultiPageFormData() | ||
| { | ||
| // Given | ||
| using var transaction = new TransactionScope(); | ||
| InsertMultiPageFormData(dataInDb); | ||
| 
     | 
||
| // When | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| dataInDb.TempDataGuid, | ||
| MultiPageFormDataFeature.AddNewCourse.Name | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().BeEquivalentTo(dataInDb); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void GetMultiPageFormDataByGuidAndFeature_returns_null_with_incorrect_guid() | ||
| { | ||
| // Given | ||
| using var transaction = new TransactionScope(); | ||
| InsertMultiPageFormData(dataInDb); | ||
| 
     | 
||
| // When | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| Guid.NewGuid(), | ||
| MultiPageFormDataFeature.AddNewCourse.Name | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().BeNull(); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void GetMultiPageFormDataByGuidAndFeature_returns_null_with_incorrect_feature() | ||
| { | ||
| // Given | ||
| using var transaction = new TransactionScope(); | ||
| InsertMultiPageFormData(dataInDb); | ||
| 
     | 
||
| // When | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| dataInDb.TempDataGuid, | ||
| "incorrect feature" | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().BeNull(); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void InsertMultiPageFormData_inserts_expected_values() | ||
| { | ||
| using var transaction = new TransactionScope(); | ||
| 
     | 
||
| // When | ||
| multiPageFormDataService.InsertMultiPageFormData(dataInDb); | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| dataInDb.TempDataGuid, | ||
| MultiPageFormDataFeature.AddNewCourse.Name | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().BeEquivalentTo(dataInDb, options => options.Excluding(d => d.Id)); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void UpdateJsonByGuid_updates_expected_value() | ||
| { | ||
| // Given | ||
| using var transaction = new TransactionScope(); | ||
| const string newJsonString = "new json"; | ||
| InsertMultiPageFormData(dataInDb); | ||
| 
     | 
||
| // When | ||
| multiPageFormDataService.UpdateJsonByGuid(dataInDb.TempDataGuid, newJsonString); | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| dataInDb.TempDataGuid, | ||
| MultiPageFormDataFeature.AddNewCourse.Name | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().NotBeNull(); | ||
| result!.Json.Should().BeEquivalentTo(newJsonString); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void UpdateJsonByGuid_does_not_update_other_records() | ||
| { | ||
| // Given | ||
| using var transaction = new TransactionScope(); | ||
| const string newJsonString = "new json"; | ||
| var secondDataInDb = Builder<MultiPageFormData> | ||
| .CreateNew() | ||
| .With(d => d.TempDataGuid = Guid.NewGuid()) | ||
| .Build(); | ||
| InsertMultiPageFormData(dataInDb); | ||
| InsertMultiPageFormData(secondDataInDb); | ||
| 
     | 
||
| // When | ||
| multiPageFormDataService.UpdateJsonByGuid(secondDataInDb.TempDataGuid, newJsonString); | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| dataInDb.TempDataGuid, | ||
| MultiPageFormDataFeature.AddNewCourse.Name | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().BeEquivalentTo(dataInDb); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void DeleteByGuid_deletes_expected_record() | ||
                
      
                  SteveJacksonSoft marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| { | ||
| // Given | ||
| using var transaction = new TransactionScope(); | ||
| InsertMultiPageFormData(dataInDb); | ||
| 
     | 
||
| // When | ||
| multiPageFormDataService.DeleteByGuid(dataInDb.TempDataGuid); | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| dataInDb.TempDataGuid, | ||
| MultiPageFormDataFeature.AddNewCourse.Name | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().BeNull(); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void DeleteByGuid_does_not_delete_other_records() | ||
| { | ||
| // Given | ||
| using var transaction = new TransactionScope(); | ||
| var secondDataInDb = Builder<MultiPageFormData> | ||
| .CreateNew() | ||
| .With(d => d.TempDataGuid = Guid.NewGuid()) | ||
| .Build(); | ||
| InsertMultiPageFormData(dataInDb); | ||
| InsertMultiPageFormData(secondDataInDb); | ||
| 
     | 
||
| // When | ||
| multiPageFormDataService.DeleteByGuid(secondDataInDb.TempDataGuid); | ||
| var result = multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature( | ||
| dataInDb.TempDataGuid, | ||
| MultiPageFormDataFeature.AddNewCourse.Name | ||
| ); | ||
| 
     | 
||
| // Then | ||
| result.Should().BeEquivalentTo(dataInDb); | ||
| } | ||
| 
     | 
||
| private void InsertMultiPageFormData(MultiPageFormData data) | ||
| { | ||
| connection.Execute( | ||
| @"SET IDENTITY_INSERT dbo.MultiPageFormData ON | ||
| INSERT MultiPageFormData (ID, TempDataGuid, Json, Feature, CreatedDate) | ||
| VALUES (@Id, @TempDataGuid, @Json, @Feature, @CreatedDate) | ||
| SET IDENTITY_INSERT dbo.MultiPageFormData OFF", | ||
| data | ||
| ); | ||
| } | ||
| } | ||
| } | ||
        
          
          
            4 changes: 2 additions & 2 deletions
          
          4 
        
  .../NewlineSeparatedStringListHelperTests.cs → .../NewlineSeparatedStringListHelperTests.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.