public async Task Guid_Data_Saved_In_DataBase_Should_Be_Properly_Restored() { ServiceCollection services = new ServiceCollectionBuilder().PrepareServiceCollectionForGuidTests(s => { s.ResetDapperCustomTypeHandlers(); s.RegisterDapperCustomTypeHandlers(Assembly.GetExecutingAssembly()); }); ServiceProvider serviceProvider = services.BuildServiceProvider(); using (IServiceScope scope = serviceProvider.CreateScope()) { var scopedServices = scope.ServiceProvider; ITestGuidRepository testGuidRepository = scopedServices.GetRequiredService <ITestGuidRepository>(); TestGuidObject testGuidObject = new TestGuidObject { GuidId = Guid.NewGuid() }; // Act await testGuidRepository.SaveTestGuidObject(testGuidObject); TestGuidObject retrievedTestGuidObject = await testGuidRepository.GetTestGuidObject(testGuidObject.Id); // Assert retrievedTestGuidObject.Should().NotBeNull(); retrievedTestGuidObject.Should().BeEquivalentTo(testGuidObject); retrievedTestGuidObject.GuidId.Should().Be(testGuidObject.GuidId); } }
public void When_Custom_Guid_Handler_Is_Registered_Exception_Should_Not_Be_Thrown() { ServiceCollection services = new ServiceCollectionBuilder().PrepareServiceCollectionForGuidTests(s => { s.ResetDapperCustomTypeHandlers(); s.RegisterDapperCustomTypeHandlers(new[] { Assembly.GetExecutingAssembly() }); }); ServiceProvider serviceProvider = services.BuildServiceProvider(); using (IServiceScope scope = serviceProvider.CreateScope()) { var scopedServices = scope.ServiceProvider; ITestGuidRepository testGuidRepository = scopedServices.GetRequiredService <ITestGuidRepository>(); TestGuidObject testGuidObject = CreateTestGuidObject(); // Assert Assert.DoesNotThrowAsync(async() => await testGuidRepository.SaveTestGuidObject(testGuidObject)); Assert.DoesNotThrowAsync(async() => await testGuidRepository.GetTestGuidObject(testGuidObject.Id)); } }