public async void CreatePostAndVerifyOk() { var client = GetClient(); var request = new RestRequest(); request.Method = Method.POST; request.Resource = "api/tools/"; request.AddHeader("Accept", "application/json"); string modelNumber = "TL" + RandomNumberHelper.NextInteger(); var theTool = new ToolModel { Name = "A Power Tool", ModelNumber = modelNumber }; request.AddJsonBody(theTool); var response = await client.Execute(request); Assert.NotNull(response); Assert.NotNull(response.Content); Assert.True(response.StatusCode == HttpStatusCode.Created); var toolModelRequest = new RestRequest { Method = Method.GET, Resource = $"api/tools/{modelNumber}" }; toolModelRequest.AddHeader("Accept", "application/json"); toolModelRequest.AddParameter("GetBy", "ModelNumber", ParameterType.HttpHeader); var toolIdResponse = await client.Execute <ToolModel>(toolModelRequest); Assert.True(toolIdResponse.IsSuccess); _host.Dispose(); }
public void VerifyDatabaseInsertOfJobWithPowerToolsTenant() { var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); var context = new JobAssistantContext(helper.Options); var ptDomain = new Tenant { DomainId = "Power Tools" }; context.Tenants.Add(ptDomain); var grindJob = new Job { Name = "Grind", DomainId = ptDomain.DomainId }; Assert.True(grindJob.JobId == 0); context.Jobs.Add(grindJob); var efDefaultId = grindJob.JobId; // Temporarily assigned by EF Assert.True(efDefaultId > 0); var savedCount = context.SaveChanges(); Assert.True(savedCount == 2); Assert.True(grindJob.JobId > 0); // New id is likely different than temporary id assigned above }
public async void RepositoryCreateDeleteCategories() { using (var context = new JobAssistantContext(_helper.Options)) { var repositoryUnderTest = new Repository(context); int firstId = RandomNumberHelper.NextInteger(); var firstCategory = await repositoryUnderTest.Create <Category>(new Category { CategoryId = firstId, Name = "Test Category " + firstId }); // Was .Result int secondId = RandomNumberHelper.NextInteger(); var secondCategory = await repositoryUnderTest.Create <Category>(new Category { CategoryId = secondId, Name = "Test Category " + secondId }); // Was .Result Assert.Equal("Test Category " + firstId, context.Categories.Single(c => c.CategoryId == firstId).Name); Assert.Equal("Test Category " + secondId, context.Categories.Single(c => c.CategoryId == secondId).Name); await repositoryUnderTest.Delete <Category>(firstCategory); var verifyCategory = repositoryUnderTest.Single <Category>(c => c.CategoryId == firstCategory.CategoryId); Assert.Null(verifyCategory); await repositoryUnderTest.Delete <Category>(secondCategory); verifyCategory = repositoryUnderTest.Single <Category>(c => c.CategoryId == secondCategory.CategoryId); Assert.Null(verifyCategory); } }
public async void CreateSimpleTenantAndVerify() { var uniqueId = RandomNumberHelper.NextInteger(); var domain = $"Orange DIY (yId={uniqueId})"; var newTenant = new TenantModel { Name = "Generic Tools Tenant", Domain = domain, Guid = Guid.NewGuid(), Description = "Do-It-Yourself tool data domain (tenant)", CreatedAt = DateTimeOffset.Now }; var response = await _client.PostAsJsonAsync("/api/tenants", newTenant); _logger.LogDebug(response.ToString()); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); _logger.LogDebug(responseString); Assert.Empty(responseString); _client.DefaultRequestHeaders.Add(TenantModel.DomainField, BoschTenants.BoschBlueDomain); response = await _client.GetAsync($"/api/tenants/{domain}"); _logger.LogDebug("HTTP GET of Tenants returned status code: " + response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); var jsonContent = await response.Content.ReadAsStringAsync(); _logger.LogDebug("HTTP GET of Tenants returned contents: " + jsonContent); Assert.False(string.IsNullOrWhiteSpace(jsonContent)); }
public async void RepositoryCreateCategoryAndJobTest() { int nextId = RandomNumberHelper.NextInteger(); using (var context = new JobAssistantContext(helper.Options)) { var category = new Category { CategoryId = nextId, Name = "Test Category " + nextId }; var job = new Job { JobId = nextId, Name = "Test Job " + nextId }; category.Jobs = new List <Job>(); category.Jobs.Add(job); var repositoryUnderTest = new Repository(context); await repositoryUnderTest.Create <Category>(category); } using (var context = new JobAssistantContext(helper.Options)) { var repositoryUnderTest = new Repository(context); var parentCategory = repositoryUnderTest.All <Category>().Include(c => c.Jobs).Single(c => c.CategoryId == nextId); Assert.NotNull(parentCategory); Assert.NotNull(parentCategory.Jobs); Assert.Equal(1, parentCategory.Jobs.Count); var childJob = parentCategory.Jobs.Single(j => j.JobId == nextId); Assert.Equal("Test Job " + nextId, childJob.Name); context.Remove(parentCategory); context.SaveChanges(); var hasCategory = context.Categories.Any(c => c.CategoryId == nextId); Assert.False(hasCategory); } }
public async void CreateUpdateAndVerify() { var client = GetClient(); var postRequest = new RestRequest(); postRequest.Method = Method.POST; postRequest.Resource = "api/categories/"; postRequest.AddHeader("Accept", "application/json"); string categoryName = "CAT" + RandomNumberHelper.NextInteger(); var theCategory = new CategoryModel { Name = categoryName }; postRequest.AddJsonBody(theCategory); var postResponse = await client.Execute(postRequest); Assert.NotNull(postResponse); Assert.NotNull(postResponse.Content); Assert.True(postResponse.StatusCode == HttpStatusCode.OK); _logger.LogDebug($"Created test category with name: {categoryName}"); var categoryModelRequest = new RestRequest { Method = Method.GET, Resource = $"api/categories/{categoryName}" }; categoryModelRequest.AddHeader("Accept", "application/json"); var categoryModelResponse = await client.Execute <CategoryModel>(categoryModelRequest); Assert.True(categoryModelResponse.IsSuccess); _logger.LogDebug($"Retrieved test category with an id of: {categoryModelResponse.Data.CategoryId}"); var updateRequest = new RestRequest(); updateRequest.Method = Method.PUT; updateRequest.Resource = $"api/categories/{categoryModelResponse.Data.CategoryId}"; updateRequest.Parameters.Clear(); updateRequest.AddHeader(TenantModel.DomainField, BoschTenants.BoschBlueDomain); updateRequest.AddHeader("Accept", "application/json"); var theUpdatedCategory = categoryModelResponse.Data; theUpdatedCategory.Name = "UPDATED_CAT" + RandomNumberHelper.NextInteger(); updateRequest.AddJsonBody(theUpdatedCategory); var updateResponse = await client.Execute(updateRequest); Assert.NotNull(updateResponse); Assert.NotNull(updateResponse.Content); Assert.True(updateResponse.StatusCode == HttpStatusCode.OK); _logger.LogDebug($"Updated test category with an id of: {theUpdatedCategory.CategoryId}"); _host.Dispose(); }
public async void CreateUpdateAndVerify() { var client = GetClient(); var postRequest = new RestRequest(); postRequest.Method = Method.POST; postRequest.Resource = "api/tools/"; postRequest.AddHeader("Accept", "application/json"); string modelNumber = "TL" + RandomNumberHelper.NextInteger(); var theTool = new ToolModel { Name = "A Power Tool", ModelNumber = modelNumber }; postRequest.AddJsonBody(theTool); var postResponse = await client.Execute(postRequest); Assert.NotNull(postResponse); Assert.NotNull(postResponse.Content); Assert.True(postResponse.StatusCode == HttpStatusCode.Created); _logger.LogDebug($"Created test tool for model id: {modelNumber}"); var toolModelRequest = new RestRequest { Method = Method.GET, Resource = $"api/tools/{modelNumber}" }; toolModelRequest.AddHeader("Accept", "application/json"); toolModelRequest.AddParameter("QueryBy", "ModelNumber", ParameterType.HttpHeader); var toolModelResponse = await client.Execute <ToolModel>(toolModelRequest); Assert.True(toolModelResponse.IsSuccess); _logger.LogDebug($"Retrieved test tool with an id of: {toolModelResponse.Data.ToolId}"); var updateRequest = new RestRequest(); updateRequest.Method = Method.PUT; updateRequest.Resource = $"api/tools/{toolModelResponse.Data.ToolId}"; updateRequest.AddHeader("Accept", "application/json"); var theUpdatedTool = toolModelResponse.Data; theUpdatedTool.Name = "A Power Tool (UPDATED)"; updateRequest.AddJsonBody(theUpdatedTool); var updateResponse = await client.Execute(updateRequest); Assert.NotNull(updateResponse); Assert.NotNull(updateResponse.Content); Assert.True(updateResponse.StatusCode == HttpStatusCode.OK); _logger.LogDebug($"Updated test tool with an id of: {theUpdatedTool.ToolId}"); _host.Dispose(); }
public async void AddCategoryJobMaterialToolAndQueryTest() { var nextId = RandomNumberHelper.NextInteger(); var parentCategory = new Category { CategoryId = nextId, Jobs = new List <Job>() }; var job = new Job { JobId = nextId, Name = "Test Job " + nextId }; var material = new Material { MaterialId = nextId, Name = "Test Material " + nextId, Tools = new List <Tool> { new Tool { ToolId = nextId, Name = "Test Tool " + nextId } } }; job.Materials = new List <Material> { material }; parentCategory.Jobs.Add(job); var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); using (var otherContext = new JobAssistantContext(helper.Options)) { var repositoryUnderCreateTest = new Repository(otherContext); await repositoryUnderCreateTest.Create <Category>(parentCategory); await repositoryUnderCreateTest.SaveChanges(); var repositoryUnderQueryTest = new Repository(otherContext); var myJob = repositoryUnderQueryTest.All <Category>().Include(c => c.Jobs).ThenInclude(m => m.Materials) .ThenInclude(t => t.Tools).Single(c => c.CategoryId == nextId).Jobs.Single(j => j.JobId == nextId); Assert.Equal("Test Job " + nextId, myJob.Name); var associatedTool = material.Tools.First(); Assert.NotNull(associatedTool); Assert.Equal(nextId, associatedTool.ToolId); repositoryUnderCreateTest.Dispose(); repositoryUnderQueryTest.Dispose(); } }
public TradeRelationshipTests() { /** * This constructor is executed prior to each [Fact]-based unit test method. * Considering this, a seperate NAMED in-memory DB is initialized. */ var dbId = RandomNumberHelper.NextInteger(); _helper = new TestContextHelper("test_in-memory_DB-" + dbId); var context = new JobAssistantContext(_helper.Options); SampleBoschToolsDataSet.SeedBoschToolTradesGraphData(context); }
public async void RepositoryCreateJobTest() { using (var context = new JobAssistantContext(_helper.Options)) { var nextId = RandomNumberHelper.NextInteger(); var repositoryUnderTest = new Repository(context); var myJob = new Job { JobId = nextId, Name = "Job Name " + nextId }; await repositoryUnderTest.Create(myJob); var verifyJob = repositoryUnderTest.Single <Job>(j => j.JobId == nextId); Assert.NotNull(verifyJob); } }
public async void RepositoryCreateTest() { using (var context = new JobAssistantContext(_helper.Options)) { int nextId = RandomNumberHelper.NextInteger(); var repositoryUnderTest = new Repository(context); var newCategory = repositoryUnderTest.Create <Category>(new Category { CategoryId = nextId, Name = "Test Category " + nextId }).Result; Assert.Equal("Test Category " + nextId, context.Categories.Single(c => c.CategoryId == nextId).Name); await repositoryUnderTest.Delete <Category>(newCategory); var verifyJob = repositoryUnderTest.Single <Category>(c => c.CategoryId == nextId); Assert.Null(verifyJob); } }
public ApplicationRelationshipTests() { /** * This constructor is executed prior to each [Fact]-based unit test method. * Considering this, a seperate NAMED in-memory DB is initialized. */ var dbId = RandomNumberHelper.NextInteger(); _helper = new TestContextHelper("test_in-memory_DB-" + dbId); _context = new JobAssistantContext(_helper.Options); /** * Add sample data with ToolsSampleData.SeedBoschToolsGraphData(_context); * or using the subset with SeedBoschToolsSubsetData(_context). */ SampleBoschToolsDataSet.SeedBoschToolsSubsetData(_context); }
public async void CreateUpdateAndVerify() { var client = GetClient(); var postRequest = RestSharpApiClientHelper.BuildBoschBlueRequest(Method.POST, "api/accessories/"); string modelNumber = "ACC" + RandomNumberHelper.NextInteger(); var theAccessory = new AccessoryModel { Name = "A Power Accessory", ModelNumber = modelNumber, TenantDomain = BoschTenants.BoschBlueDomain }; postRequest.AddJsonBody(theAccessory); var postResponse = await client.Execute(postRequest); Assert.NotNull(postResponse); Assert.NotNull(postResponse.Content); Assert.True(postResponse.StatusCode == HttpStatusCode.Created); _logger.LogDebug($"Created test accessory for model id: {modelNumber}"); var accessoryModelRequest = RestSharpApiClientHelper.BuildBoschBlueRequest(Method.GET, $"api/accessories/{modelNumber}"); accessoryModelRequest.AddParameter("QueryBy", "ModelNumber", ParameterType.HttpHeader); var accessoryModelResponse = await client.Execute <AccessoryModel>(accessoryModelRequest); Assert.True(accessoryModelResponse.IsSuccess); _logger.LogDebug($"Retrieved test accessory with an id of: {accessoryModelResponse.Data.AccessoryId}"); var updateRequest = RestSharpApiClientHelper.BuildBoschBlueRequest(Method.PUT, $"api/accessories/{accessoryModelResponse.Data.AccessoryId}"); var theUpdatedAccessory = accessoryModelResponse.Data; theUpdatedAccessory.Name = "A Power Accessory (UPDATED)"; updateRequest.AddJsonBody(theUpdatedAccessory); var updateResponse = await client.Execute(updateRequest); Assert.NotNull(updateResponse); Assert.NotNull(updateResponse.Content); Assert.True(updateResponse.StatusCode == HttpStatusCode.OK); _logger.LogDebug($"Updated test accessory with an id of: {theUpdatedAccessory.AccessoryId}"); _host.Dispose(); }
public void VerifyDatabaseInsertOfNewApplication() { var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); var context = new JobAssistantContext(helper.Options); var application = new Application { Name = "Level" }; Assert.True(application.ApplicationId == 0); context.Applications.Add(application); var efDefaultId = application.ApplicationId; Assert.True(efDefaultId > 0); var savedCount = context.SaveChanges(); Assert.True(savedCount == 1); Assert.True(application.ApplicationId > 0); }
public void VerifyDatabaseInsertOfNewTrade() { var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); var context = new JobAssistantContext(helper.Options); var autoTrade = new Trade { Name = "Automotive and Other Vehicle Maintenance" }; Assert.True(autoTrade.TradeId == 0); context.Trades.Add(autoTrade); var efDefaultId = autoTrade.TradeId; Assert.True(efDefaultId > 0); var savedCount = context.SaveChanges(); Assert.True(savedCount == 1); Assert.True(autoTrade.TradeId > 0); }
public void AddAndUpdateMaterialsWithJobsDbSetQueryTest() { var nextId = RandomNumberHelper.NextInteger(); var parentCategory = new Category(); parentCategory.CategoryId = nextId; parentCategory.Name = "Test Category " + nextId; parentCategory.Jobs = new List <Job>(); var job = new Job { JobId = nextId, Name = "Test Job " + nextId }; var material = new Material { MaterialId = nextId, Name = "Test Material " + nextId }; job.Materials = new List <Material>(); job.Materials.Add(material); parentCategory.Jobs.Add(job); var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); using (var saveContext = new JobAssistantContext(helper.Options)) { saveContext.Add(parentCategory); var entitiesPeristed = saveContext.SaveChanges(); Assert.Equal(3, entitiesPeristed); // Expect 3 because a category, job and material are being persisted. } using (var queryContext = new JobAssistantContext(helper.Options)) { var myJob = queryContext.Jobs.Include(j => j.Materials).Single(j => j.JobId == nextId); Assert.Equal("Test Job " + nextId, myJob.Name); Assert.True(myJob.Materials.Count == 1); var someMaterial = queryContext.Materials.Single(m => m.MaterialId == nextId); Assert.Equal("Test Material " + nextId, someMaterial.Name); var expectedCategoryName = "Test Category " + nextId; var topCategory = queryContext.Categories.Single(c => c.CategoryId == nextId); Assert.Equal(expectedCategoryName, topCategory.Name); } }
public void VerifyDatabaseInsertOfCategory() { var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); var context = new JobAssistantContext(helper.Options); var dremelMultiPurposeCategory = new Category() { Name = "Multi-Purpose" }; Assert.True(dremelMultiPurposeCategory.CategoryId == 0); context.Categories.Add(dremelMultiPurposeCategory); var efDefaultId = dremelMultiPurposeCategory.CategoryId; // Temporarily assigned by EF Assert.True(efDefaultId > 0); int savedCount = context.SaveChanges(); Assert.True(savedCount == 1); Assert.True(dremelMultiPurposeCategory.CategoryId > 0); // New id is likely different than temporary id assigned above }
public async void RepositoryUpdateJobTest() { using (var context = new JobAssistantContext(_helper.Options)) { var repositoryUnderTest = new Repository(context); var nextId = RandomNumberHelper.NextInteger(); var myJob = new Job { JobId = nextId, Name = "Job Name " + nextId }; await repositoryUnderTest.Create(myJob); var jobName = "Updated Job Name " + nextId; myJob.Name = jobName; var updateCount = await repositoryUnderTest.Update(myJob); Assert.True(updateCount == 1); var verifyJob = repositoryUnderTest.Single <Job>(j => j.JobId == nextId); Assert.NotNull(verifyJob); Assert.Equal(jobName, verifyJob.Name); } }
public async void RepositoryCreateTest() { using (var context = new JobAssistantContext(_helper.Options)) { int nextId = RandomNumberHelper.NextInteger(); var repositoryUnderTest = new Repository(context); var newTool = new Tool() { ToolId = nextId, Name = "RH850VC 1 - 7 / 8 In.SDS - max® Rotary Hammer", ModelNumber = "RH850VC" }; await repositoryUnderTest.Create(newTool); Assert.Equal("RH850VC 1 - 7 / 8 In.SDS - max® Rotary Hammer", context.Tools.Single(t => t.ToolId == nextId).Name); await repositoryUnderTest.Delete(newTool); var verifiedTool = repositoryUnderTest.Single <Tool>(c => c.ToolId == nextId); Assert.Null(verifiedTool); } }
public async void RepositoryCreateTest() { using (var context = new JobAssistantContext(_helper.Options)) { int nextId = RandomNumberHelper.NextInteger(); var repositoryUnderTest = new Repository(context); var newAccessory = new Accessory() { AccessoryId = nextId, Name = "HCBG501T 5 pc.BlueGranite™ Turbo Carbide Hammer Drill Bits Set", ModelNumber = "HCBG501T" }; await repositoryUnderTest.Create(newAccessory); Assert.Equal("HCBG501T 5 pc.BlueGranite™ Turbo Carbide Hammer Drill Bits Set", context.Accessories.Single(c => c.AccessoryId == nextId).Name); await repositoryUnderTest.Delete(newAccessory); var verifiedAccessory = repositoryUnderTest.Single <Accessory>(c => c.AccessoryId == nextId); Assert.Null(verifiedAccessory); } }
public void VerifyDatabaseInsertOfPowerTool() { var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); var context = new JobAssistantContext(helper.Options); var hammerDrill = new Tool { Name = "Variable Speed Hammer Drill Kit", ModelNumber = "1191VSRK", Attributes = "{ \"Weight\" : \"7.8 pounds\", \"Package Dimensions\" = \"14 x 11.9 x 4.3 inches\", \"Color\" = \"Blue\" }", MaterialNumber = "B000VZJGAO" }; Assert.True(hammerDrill.ToolId == 0); context.Tools.Add(hammerDrill); var efDefaultId = hammerDrill.ToolId; // Temporarily assigned by EF Assert.True(efDefaultId > 0); int savedCount = context.SaveChanges(); Assert.True(savedCount == 1); Assert.True(hammerDrill.ToolId > 0); // New id is likely different than temporary id assigned above }
private void SetupTestToolData() { var toolId = RandomNumberHelper.NextInteger(); var tool = new Tool { ToolId = toolId, Name = "Hammer Tool " + toolId }; var materialId = RandomNumberHelper.NextInteger(); var material = new Material { MaterialId = materialId, Name = "Material " + materialId, Tools = new List <Tool> { tool } }; var jobId = RandomNumberHelper.NextInteger(); var job = new Job { JobId = jobId, Name = "Job " + jobId, Materials = new List <Material> { material } }; var categoryId = RandomNumberHelper.NextInteger(); var category = new Category { CategoryId = categoryId, Name = "Category " + categoryId, Jobs = new List <Job> { job } }; context.Add(category); context.SaveChanges(); toolUnderTest = tool; }
public async void RepositoryCreateDeleteCategoryAndMultipleJobsTest() { int categoryId; using (var context = new JobAssistantContext(helper.Options)) { categoryId = RandomNumberHelper.NextInteger(); var category = new Category { CategoryId = categoryId, Name = "Test Category " + categoryId }; category.Jobs = new List <Job>(); int jobId = RandomNumberHelper.NextInteger(); var job1 = new Job { JobId = jobId, Name = "Test Job " + jobId }; category.Jobs.Add(job1); jobId = RandomNumberHelper.NextInteger(); var job2 = new Job { JobId = jobId, Name = "Test Job " + jobId }; category.Jobs.Add(job2); var repositoryUnderTest = new Repository(context); var parentCategory = repositoryUnderTest.Create <Category>(category); Assert.Equal(2, category.Jobs.Count); } using (var context = new JobAssistantContext(helper.Options)) { int initialCount = context.Categories.Count(); var repositoryUnderTest = new Repository(context); var parentCategory = repositoryUnderTest.All <Category>().Include(c => c.Jobs).Single(c => c.CategoryId == categoryId); Assert.NotNull(parentCategory); Assert.NotNull(parentCategory.Jobs); await repositoryUnderTest.Delete(parentCategory); var hasCategory = repositoryUnderTest.All <Category>().Any(c => c.CategoryId == categoryId); Assert.False(hasCategory); } }
public void AddAndUpdateMaterialsWithIncludesAndTraversalTest() { var nextId = RandomNumberHelper.NextInteger(); var parentCategory = new Category(); parentCategory.CategoryId = nextId; parentCategory.Jobs = new List <Job>(); var job = new Job { JobId = nextId, Name = "Test Job " + nextId }; var material = new Material { MaterialId = nextId, Name = "Test Material " + nextId }; job.Materials = new List <Material>(); job.Materials.Add(material); parentCategory.Jobs.Add(job); var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); using (var context = new JobAssistantContext(helper.Options)) { context.Add(parentCategory); var entitiesPeristed = context.SaveChanges(); Assert.Equal(3, entitiesPeristed); // Expect 3 because a category, job and material are being persisted. } using (var context = new JobAssistantContext(helper.Options)) { var myJob = context.Categories.Include(c => c.Jobs).ThenInclude(m => m.Materials) .ThenInclude(t => t.Tools).Single(c => c.CategoryId == nextId).Jobs.Single(j => j.JobId == nextId); Assert.Equal("Test Job " + nextId, myJob.Name); } }
public void VerifyDatabaseInsertOfAccessoryBit() { var helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); var context = new JobAssistantContext(helper.Options); var bit = new Accessory { Name = "5/16 In. x 12 In. Bell Hanger Bits", ModelNumber = "BH1002", Attributes = "{ \"Weight\" : \"2.4 ounces\", \"Size\" = \"5/16-Inch\", \"Color\" = \"Blue\" }", SocialRating = 5M, MaterialNumber = "B000WA3M9E" }; Assert.True(bit.AccessoryId == 0); context.Accessories.Add(bit); var efDefaultId = bit.AccessoryId; // Temporarily assigned by EF Assert.True(efDefaultId > 0); int savedCount = context.SaveChanges(); Assert.True(savedCount == 1); Assert.True(bit.AccessoryId > 0); // New id is likely different than temporary id assigned above }
public async void RepositoryCreateUpdateDeleteCategoryAndJobTests() { int categoryId = RandomNumberHelper.NextInteger(); int jobId; using (var context = new JobAssistantContext(helper.Options)) { var repositoryUnderTest = new Repository(context); var category = new Category { CategoryId = categoryId, Name = "Test Category " + categoryId }; jobId = RandomNumberHelper.NextInteger(); var job = new Job { JobId = jobId, Name = "Test Job " + jobId }; category.Jobs = new List <Job>(); category.Jobs.Add(job); await repositoryUnderTest.Create <Category>(category); } using (var context = new JobAssistantContext(helper.Options)) { var repositoryUnderTest = new Repository(context); var parentCategory = repositoryUnderTest.All <Category>().Include(c => c.Jobs).Single(c => c.CategoryId == categoryId); Assert.NotNull(parentCategory); Assert.NotNull(parentCategory.Jobs); Assert.Equal(1, parentCategory.Jobs.Count); var jobToUpdate = parentCategory.Jobs.Single(j => j.JobId == jobId); jobToUpdate.Name = "Updated Test Job " + jobId; Assert.Equal("Updated Test Job " + jobId, parentCategory.Jobs.Single(j => j.JobId == jobId).Name); await repositoryUnderTest.Update(jobToUpdate); // TODO: Add assertion await repositoryUnderTest.Delete(parentCategory); var hasCategory = repositoryUnderTest.All <Category>().Any(c => c.CategoryId == categoryId); Assert.False(hasCategory); } }
public async void AddCategoryJobMaterialAndQueryTest() { var nextId = RandomNumberHelper.NextInteger(); var parentCategory = new Category { CategoryId = nextId, Jobs = new List <Job>() }; var job = new Job { JobId = nextId, Name = "Test Job " + nextId }; var material = new Material { MaterialId = nextId, Name = "Test Material " + nextId }; job.Materials = new List <Material> { material }; parentCategory.Jobs.Add(job); using (var context = new JobAssistantContext(_helper.Options)) { var repositoryUnderTest = new Repository(context); await repositoryUnderTest.Create(parentCategory); await repositoryUnderTest.SaveChanges(); var myJob = repositoryUnderTest.All <Category>().Include(c => c.Jobs).ThenInclude(m => m.Materials) .ThenInclude(t => t.Tools).Single(c => c.CategoryId == nextId).Jobs.Single(j => j.JobId == nextId); Assert.Equal("Test Job " + nextId, myJob.Name); } }
public void RepositoryCreateFetchListOfCategoriesTest() { using (var context = new JobAssistantContext(_helper.Options)) { ICollection <int> verifySelectIds = new List <int>(); var repositoryUnderTest = new Repository(context); for (int i = 0, nextId = RandomNumberHelper.NextInteger(); i < 10; i++) { int categoryId = nextId + i; if (i == 4 || i == 6) { verifySelectIds.Add(categoryId); } var testCategoryCreated = repositoryUnderTest.Create <Category>(new Category { CategoryId = categoryId, Name = "Test Category " + categoryId }); Assert.NotNull(testCategoryCreated); } context.SaveChanges(); Assert.NotNull(context.Categories); var categoryCount = context.Categories.Count(); Assert.True(categoryCount == 10); Assert.NotNull(context.Categories.First()); Assert.NotNull(context.Categories.Last()); var enumerator = verifySelectIds.GetEnumerator(); while (enumerator.MoveNext()) { int nextCategoryId = enumerator.Current; var verifyCategory = repositoryUnderTest.Single <Category>(c => c.CategoryId == nextCategoryId); Assert.NotNull(verifyCategory); } enumerator.Dispose(); } }
public ToolRepositoryTests() { _helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); }
public MaterialRepositoryTests() { this._helper = new TestContextHelper("test_in-memory_DB-" + RandomNumberHelper.NextInteger()); }