private FakeTestDataModel CreateRandomTestDataModel(Guid dataModelId = default) { return(new FakeTestDataModel { Id = dataModelId == Guid.Empty ? Guid.NewGuid() : dataModelId, Name = RandomValueGenerator.CreateRandomString(20, 40), Date = RandomValueGenerator.CreateRandomDate(), SomeField = RandomValueGenerator.CreateRandomString(30, 60) }); }
public void GetThuriaDataModelConditions_GivenDataModelWithNoConditions_ShouldReturnEmptyConditionList(DbContextAction DbContextAction) { //---------------Set up test pack------------------- var dataModel = new ThuriaPocoDataModel { Id = Guid.NewGuid(), Name = RandomValueGenerator.CreateRandomString(), Description = RandomValueGenerator.CreateRandomString(), ModifiedDate = RandomValueGenerator.CreateRandomDate(), IsActive = true }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var allConditions = dataModel.GetThuriaDataModelConditions(DbContextAction); //---------------Test Result ----------------------- var dataModelConditions = allConditions.ToList(); dataModelConditions.Should().NotBeNull(); dataModelConditions.Count.Should().Be(0); }
public void BuildInsertStatement_GivenDataModel_ShouldBuildExpectedStatement() { //---------------Set up test pack------------------- FakeTestDataModel dataModel = new FakeTestDataModel { Id = Guid.NewGuid(), Name = RandomValueGenerator.CreateRandomString(10, 20), Date = RandomValueGenerator.CreateRandomDate(), SomeField = RandomValueGenerator.CreateRandomString(15, 30) }; var expectedStatement = "INSERT INTO [FakeTest] ([Id],[Name],[Date],[SomeFieldAlias]) " + $"VALUES ('{dataModel.Id}','{dataModel.Name}','{dataModel.Date}','{dataModel.SomeField}')"; var buildProvider = CreateProvider(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- // ReSharper disable once ExpressionIsAlwaysNull var insertStatement = buildProvider.BuildInsertStatement(dataModel); //---------------Test Result ----------------------- insertStatement.Trim().Should().Be(expectedStatement); }
public async Task PopulateAsync_GivenGenericType_ShouldCreateAndPopulateDataModelAsExpected() { //---------------Set up test pack------------------- var sourceData = new Dictionary <string, object> { { "Id", Guid.NewGuid() }, { "Name", RandomValueGenerator.CreateRandomString(10, 30) }, { "Date", RandomValueGenerator.CreateRandomDate() }, { "SomeFieldAlias", RandomValueGenerator.CreateRandomString(30, 50) } }; var dataModelPopulateProvider = new SqlDataModelPopulateProvider(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var dataModel = await dataModelPopulateProvider.PopulateAsync <FakeTestDataModel>(sourceData, DbContextAction.Retrieve); //---------------Test Result ----------------------- dataModel.Should().NotBeNull(); dataModel.Id.Should().Be((Guid)sourceData["Id"]); dataModel.Name.Should().Be((string)sourceData["Name"]); dataModel.Date.Should().Be((DateTime)sourceData["Date"]); dataModel.SomeField.Should().Be((string)sourceData["SomeFieldAlias"]); }
public void GetThuriaPopulatedRelationshipMetadata_GivenDataModelWithRelationships_ShouldReturnListOfRelationships() { //---------------Set up test pack------------------- var dataModel = new ThuriaTestDataModel { Id = Guid.NewGuid(), Name = RandomValueGenerator.CreateRandomString(), Description = RandomValueGenerator.CreateRandomString(), ModifiedDate = RandomValueGenerator.CreateRandomDate(), IsActive = true, ForeignTestDataModel = new ThuriaForeignTestDataModel(), AllForeignTests = new List <ThuriaForeignTestDataModel> { new ThuriaForeignTestDataModel() } }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var modelRelationships = dataModel.GetThuriaPopulatedRelationshipMetadata(); //---------------Test Result ----------------------- var thuriaRelationshipAttributes = modelRelationships.ToList(); thuriaRelationshipAttributes.Should().NotBeNull(); thuriaRelationshipAttributes.Count.Should().Be(2); }