From 184491d3b8376c9142fd9d3fe0e5adb5c2763cf5 Mon Sep 17 00:00:00 2001 From: RossStewart Date: Fri, 19 Nov 2021 16:25:57 +0000 Subject: [PATCH] PartTemplate work (#293) * Add new Part Template Repo/response processor. Allow to search by ID back end work. * partstemplate fixes/formatting * add put/post integration tests * typo in string * parttemplate facadeservice tests * parttemplate test updates * additional minor change for PartTemplate test Co-authored-by: rosss --- src/Domain.LinnApps/Parts/PartTemplate.cs | 6 ++ .../PartTemplateResourceBuilder.cs | 12 ++- src/Facade/Services/PartTemplateService.cs | 39 ++++++- .../Repositories/PartTemplateRepository.cs | 3 +- src/Persistence.LinnApps/ServiceDbContext.cs | 3 + src/Resources/Parts/PartTemplateResource.cs | 6 ++ src/Service.Host/client/src/actions/index.js | 2 + .../client/src/actions/partTemplateActions.js | 12 +++ .../client/src/containers/parts/Part.js | 4 +- .../client/src/containers/parts/Parts.js | 4 +- src/Service.Host/client/src/itemTypes.js | 6 ++ src/Service.Host/client/src/reducers/index.js | 2 + .../client/src/reducers/parts/partTemplate.js | 14 +++ .../src/selectors/partTemplateSelectors.js | 4 + src/Service/Modules/PartsModule.cs | 26 +++++ .../PartTemplateResponseProcessor.cs | 15 +++ .../PartsModuleSpecs/ContextBase.cs | 1 + .../WhenAddingPartTemplate.cs | 92 ++++++++++++++++ .../WhenGettingPartTemplateById .cs | 51 +++++++++ .../WhenUpdatingPartTemplate.cs | 94 ++++++++++++++++ .../ContextBase.cs | 27 +++++ .../WhenAdding.cs | 74 +++++++++++++ .../WhenGettingById.cs | 69 ++++++++++++ .../WhenUpdating.cs | 100 ++++++++++++++++++ 24 files changed, 659 insertions(+), 7 deletions(-) create mode 100644 src/Service.Host/client/src/actions/partTemplateActions.js create mode 100644 src/Service.Host/client/src/reducers/parts/partTemplate.js create mode 100644 src/Service.Host/client/src/selectors/partTemplateSelectors.js create mode 100644 src/Service/ResponseProcessors/PartTemplateResponseProcessor.cs create mode 100644 tests/Integration/Service.Tests/PartsModuleSpecs/WhenAddingPartTemplate.cs create mode 100644 tests/Integration/Service.Tests/PartsModuleSpecs/WhenGettingPartTemplateById .cs create mode 100644 tests/Integration/Service.Tests/PartsModuleSpecs/WhenUpdatingPartTemplate.cs create mode 100644 tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/ContextBase.cs create mode 100644 tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenAdding.cs create mode 100644 tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenGettingById.cs create mode 100644 tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenUpdating.cs diff --git a/src/Domain.LinnApps/Parts/PartTemplate.cs b/src/Domain.LinnApps/Parts/PartTemplate.cs index b3f14748a..304179220 100644 --- a/src/Domain.LinnApps/Parts/PartTemplate.cs +++ b/src/Domain.LinnApps/Parts/PartTemplate.cs @@ -12,6 +12,10 @@ public class PartTemplate public int? NextNumber { get; set; } + public string AllowVariants { get; set; } + + public string Variants { get; set; } + public string AccountingCompany { get; set; } public string ProductCode { get; set; } @@ -22,6 +26,8 @@ public class PartTemplate public string BomType { get; set; } + public string RmFg { get; set; } + public string AssemblyTechnology { get; set; } public string AllowPartCreation { get; set; } diff --git a/src/Facade/ResourceBuilders/PartTemplateResourceBuilder.cs b/src/Facade/ResourceBuilders/PartTemplateResourceBuilder.cs index 1a831c4e5..1fbeb41a8 100644 --- a/src/Facade/ResourceBuilders/PartTemplateResourceBuilder.cs +++ b/src/Facade/ResourceBuilders/PartTemplateResourceBuilder.cs @@ -1,6 +1,8 @@ namespace Linn.Stores.Facade.ResourceBuilders { + using System.Collections.Generic; using Linn.Common.Facade; + using Linn.Common.Resources; using Linn.Stores.Domain.LinnApps.Parts; using Linn.Stores.Resources.Parts; @@ -15,10 +17,13 @@ public PartTemplateResource Build(PartTemplate model) HasDataSheet = model.HasDataSheet, HasNumberSequence = model.HasNumberSequence, NextNumber = model.NextNumber, + AllowVariants = model.AllowVariants, + Variants = model.Variants, AccountingCompany = model.AccountingCompany, ProductCode = model.ProductCode, StockControlled = model.StockControlled, LinnProduced = model.LinnProduced, + RmFg = model.RmFg, BomType = model.BomType, AssemblyTechnology = model.AssemblyTechnology, AllowPartCreation = model.AllowPartCreation, @@ -30,7 +35,12 @@ public PartTemplateResource Build(PartTemplate model) public string GetLocation(PartTemplate model) { - throw new System.NotImplementedException(); + return $"/inventory/part-templates/{model.PartRoot}"; + } + + private IEnumerable BuildLinks(PartTemplate model) + { + yield return new LinkResource { Rel = "self", Href = this.GetLocation(model) }; } } } diff --git a/src/Facade/Services/PartTemplateService.cs b/src/Facade/Services/PartTemplateService.cs index 9bac5c4d7..67d996920 100644 --- a/src/Facade/Services/PartTemplateService.cs +++ b/src/Facade/Services/PartTemplateService.cs @@ -17,12 +17,47 @@ public PartTemplateService(IRepository repository, ITransa protected override PartTemplate CreateFromResource(PartTemplateResource resource) { - throw new NotImplementedException(); + var partTemplate = new PartTemplate + { + PartRoot = resource.PartRoot, + Description = resource.Description, + HasDataSheet = resource.HasDataSheet, + HasNumberSequence = resource.HasNumberSequence, + NextNumber = resource.NextNumber, + AllowVariants = resource.AllowVariants, + Variants = resource.Variants, + AccountingCompany = resource.AccountingCompany, + ProductCode = resource.ProductCode, + StockControlled = resource.StockControlled, + LinnProduced = resource.LinnProduced, + BomType = resource.BomType, + RmFg = resource.RmFg, + AssemblyTechnology = resource.AssemblyTechnology, + AllowPartCreation = resource.AllowPartCreation, + ParetoCode = resource.ParetoCode + }; + + return partTemplate; } protected override void UpdateFromResource(PartTemplate entity, PartTemplateResource updateResource) { - throw new NotImplementedException(); + entity.PartRoot = updateResource.PartRoot; + entity.Description = updateResource.Description; + entity.HasDataSheet = updateResource.HasDataSheet; + entity.HasNumberSequence = updateResource.HasNumberSequence; + entity.NextNumber = updateResource.NextNumber; + entity.AllowVariants = updateResource.AllowVariants; + entity.Variants = updateResource.Variants; + entity.AccountingCompany = updateResource.AccountingCompany; + entity.ProductCode = updateResource.ProductCode; + entity.StockControlled = updateResource.StockControlled; + entity.LinnProduced = updateResource.LinnProduced; + entity.BomType = updateResource.BomType; + entity.RmFg = updateResource.RmFg; + entity.AssemblyTechnology = updateResource.AssemblyTechnology; + entity.AllowPartCreation = updateResource.AllowPartCreation; + entity.ParetoCode = updateResource.ParetoCode; } protected override Expression> SearchExpression(string searchTerm) diff --git a/src/Persistence.LinnApps/Repositories/PartTemplateRepository.cs b/src/Persistence.LinnApps/Repositories/PartTemplateRepository.cs index 900f7f968..4ef6bf1dc 100644 --- a/src/Persistence.LinnApps/Repositories/PartTemplateRepository.cs +++ b/src/Persistence.LinnApps/Repositories/PartTemplateRepository.cs @@ -22,7 +22,6 @@ public PartTemplate FindById(string key) { return this.serviceDbContext .PartTemplates - .AsNoTracking() .Where(p => p.PartRoot == key) .ToList() .FirstOrDefault(); @@ -35,7 +34,7 @@ public IQueryable FindAll() public void Add(PartTemplate entity) { - throw new NotImplementedException(); + this.serviceDbContext.PartTemplates.Add(entity); } public void Remove(PartTemplate entity) diff --git a/src/Persistence.LinnApps/ServiceDbContext.cs b/src/Persistence.LinnApps/ServiceDbContext.cs index 24fe30933..09c0abed4 100644 --- a/src/Persistence.LinnApps/ServiceDbContext.cs +++ b/src/Persistence.LinnApps/ServiceDbContext.cs @@ -686,11 +686,14 @@ private void BuildPartTemplates(ModelBuilder builder) e.Property(p => p.StockControlled).HasColumnName("STOCK_CONTROLLED").HasMaxLength(1); e.Property(p => p.LinnProduced).HasColumnName("LINN_PRODUCED").HasMaxLength(1); e.Property(p => p.BomType).HasColumnName("BOM_TYPE").HasMaxLength(1); + e.Property(p => p.RmFg).HasColumnName("RM_FG").HasMaxLength(1); e.Property(p => p.ParetoCode).HasColumnName("PARETO_CODE").HasMaxLength(2); e.Property(p => p.AssemblyTechnology).HasColumnName("ASSEMBLY_TECHNOLOGY"); e.Property(p => p.HasDataSheet).HasColumnName("HAS_DATASHEET").HasMaxLength(1); e.Property(p => p.HasNumberSequence).HasColumnName("NUMBER_SEQUENCE").HasMaxLength(1); e.Property(p => p.NextNumber).HasColumnName("NEXT_NUMBER"); + e.Property(p => p.AllowVariants).HasColumnName("ALLOW_VARIANTS").HasMaxLength(1); + e.Property(p => p.Variants).HasColumnName("VARIANTS").HasMaxLength(255); e.Property(p => p.ProductCode).HasColumnName("PRODUCT_CODE").HasMaxLength(10); e.Property(p => p.AllowPartCreation).HasColumnName("ALLOW_PART_CREATION").HasMaxLength(1); e.Property(p => p.AccountingCompany).HasColumnName("ACCOUNTING_COMPANY"); diff --git a/src/Resources/Parts/PartTemplateResource.cs b/src/Resources/Parts/PartTemplateResource.cs index 728cc4043..468df9ef9 100644 --- a/src/Resources/Parts/PartTemplateResource.cs +++ b/src/Resources/Parts/PartTemplateResource.cs @@ -12,6 +12,10 @@ public class PartTemplateResource public int? NextNumber { get; set; } + public string AllowVariants { get; set; } + + public string Variants { get; set; } + public string AccountingCompany { get; set; } public string ProductCode { get; set; } @@ -22,6 +26,8 @@ public class PartTemplateResource public string BomType { get; set; } + public string RmFg { get; set; } + public string AssemblyTechnology { get; set; } public string AllowPartCreation { get; set; } diff --git a/src/Service.Host/client/src/actions/index.js b/src/Service.Host/client/src/actions/index.js index 2d7f7a6e6..63a69aa87 100644 --- a/src/Service.Host/client/src/actions/index.js +++ b/src/Service.Host/client/src/actions/index.js @@ -20,6 +20,8 @@ export const rootProductsActionTypes = makeActionTypes(itemTypes.rootProducts.ac export const partCategoriesActionTypes = makeActionTypes(itemTypes.partCategories.actionType); +export const partTemplateActionTypes = makeActionTypes(itemTypes.partTemplate.actionType); + export const partTemplatesActionTypes = makeActionTypes(itemTypes.partTemplates.actionType); export const partLiveTestActionTypes = makeActionTypes(itemTypes.partLiveTest.actionType); diff --git a/src/Service.Host/client/src/actions/partTemplateActions.js b/src/Service.Host/client/src/actions/partTemplateActions.js new file mode 100644 index 000000000..fdcaaf514 --- /dev/null +++ b/src/Service.Host/client/src/actions/partTemplateActions.js @@ -0,0 +1,12 @@ +import { UpdateApiActions } from '@linn-it/linn-form-components-library'; +import { partTemplateActionTypes as actionTypes } from './index'; +import * as itemTypes from '../itemTypes'; +import config from '../config'; + +export default new UpdateApiActions( + itemTypes.partTemplate.item, + itemTypes.partTemplate.actionType, + itemTypes.partTemplate.uri, + actionTypes, + config.appRoot +); diff --git a/src/Service.Host/client/src/containers/parts/Part.js b/src/Service.Host/client/src/containers/parts/Part.js index d62906348..acebc787c 100644 --- a/src/Service.Host/client/src/containers/parts/Part.js +++ b/src/Service.Host/client/src/containers/parts/Part.js @@ -20,8 +20,10 @@ import partCategoriesSelectors from '../../selectors/partCategoriesSelectors'; import sernosSequencesSelectors from '../../selectors/sernosSequencesSelectors'; import suppliersSelectors from '../../selectors/suppliersSelectors'; import unitsOfMeasureSelectors from '../../selectors/unitsOfMeasureSelectors'; +import partTemplateActions from '../../actions/partTemplateActions'; import partTemplatesActions from '../../actions/partTemplatesActions'; import partTemplateSelectors from '../../selectors/partTemplatesSelectors'; +import partTemplatesSelectors from '../../selectors/partTemplatesSelectors'; import { getPrivileges, getUserName, getUserNumber } from '../../selectors/userSelectors'; import * as itemTypes from '../../itemTypes'; import partLiveTestSelectors from '../../selectors/partLiveTestSelectors'; @@ -49,7 +51,7 @@ const mapStateToProps = (state, { match, location }) => ({ userName: getUserName(state), userNumber: getUserNumber(state), templateName: queryString.parse(location?.search)?.template, - partTemplates: partTemplateSelectors.getItems(state), + partTemplates: partTemplatesSelectors.getItems(state), liveTest: creating(match) ? null : partLiveTestSelectors.getItem(state), partsSearchResults: partsSelectors.getSearchItems(state), previousPaths: getPreviousPaths(state) diff --git a/src/Service.Host/client/src/containers/parts/Parts.js b/src/Service.Host/client/src/containers/parts/Parts.js index 4afc2aaaf..6b289fd8c 100644 --- a/src/Service.Host/client/src/containers/parts/Parts.js +++ b/src/Service.Host/client/src/containers/parts/Parts.js @@ -6,13 +6,15 @@ import partsSelectors from '../../selectors/partsSelectors'; import { getPrivileges } from '../../selectors/userSelectors'; import partTemplatesActions from '../../actions/partTemplatesActions'; import partTemplatesSelectors from '../../selectors/partTemplatesSelectors'; +import partTemplateSelectors from '../../selectors/partTemplateSelectors'; const mapStateToProps = (state, { match }) => ({ linkToSources: match?.url?.endsWith('/sources'), items: partsSelectors.getSearchItems(state), loading: partsSelectors.getSearchLoading(state), privileges: getPrivileges(state), - partTemplates: partTemplatesSelectors.getItems(state) + partTemplates: partTemplatesSelectors.getItems(state), + partTemplate: partTemplateSelectors.getItem(state) }); const initialise = () => dispatch => { diff --git a/src/Service.Host/client/src/itemTypes.js b/src/Service.Host/client/src/itemTypes.js index 27f38b380..5d83e04a2 100644 --- a/src/Service.Host/client/src/itemTypes.js +++ b/src/Service.Host/client/src/itemTypes.js @@ -24,6 +24,12 @@ export const partCategories = new ItemType( '/inventory/part-categories' ); +export const partTemplate = new ItemType( + 'partTemplate', + 'PART_TEMPLATE', + '/inventory/part-templates' +); + export const partTemplates = new ItemType( 'partTemplates', 'PART_TEMPLATES', diff --git a/src/Service.Host/client/src/reducers/index.js b/src/Service.Host/client/src/reducers/index.js index c9ca5f5fe..ceb4d3187 100644 --- a/src/Service.Host/client/src/reducers/index.js +++ b/src/Service.Host/client/src/reducers/index.js @@ -12,6 +12,7 @@ import accountingCompanies from './accountingCompanies'; import nominal from './nominal'; import parts from './parts/parts'; import part from './parts/part'; +import partTemplate from './parts/partTemplate'; import partTemplates from './parts/partTemplates'; import partLiveTest from './parts/partLiveTest'; import partCategories from './partCategories'; @@ -203,6 +204,7 @@ const rootReducer = history => partLiveTest, parts, partStorageTypes, + partTemplate, partTemplates, pickItemsAllocation, ports, diff --git a/src/Service.Host/client/src/reducers/parts/partTemplate.js b/src/Service.Host/client/src/reducers/parts/partTemplate.js new file mode 100644 index 000000000..c6eb5d28b --- /dev/null +++ b/src/Service.Host/client/src/reducers/parts/partTemplate.js @@ -0,0 +1,14 @@ +import { collectionStoreFactory } from '@linn-it/linn-form-components-library'; +import { partTemplateActionTypes as actionTypes } from '../../actions'; +import * as itemTypes from '../../itemTypes'; + +const defaultState = { + loading: false, + items: [] +}; + +export default collectionStoreFactory( + itemTypes.partTemplate.actionType, + actionTypes, + defaultState +); diff --git a/src/Service.Host/client/src/selectors/partTemplateSelectors.js b/src/Service.Host/client/src/selectors/partTemplateSelectors.js new file mode 100644 index 000000000..6404c96f7 --- /dev/null +++ b/src/Service.Host/client/src/selectors/partTemplateSelectors.js @@ -0,0 +1,4 @@ +import { ItemSelectors } from '@linn-it/linn-form-components-library'; +import * as itemTypes from '../itemTypes'; + +export default new ItemSelectors(itemTypes.partTemplate.item); diff --git a/src/Service/Modules/PartsModule.cs b/src/Service/Modules/PartsModule.cs index 6f9d3a4e7..31c1f17e3 100644 --- a/src/Service/Modules/PartsModule.cs +++ b/src/Service/Modules/PartsModule.cs @@ -95,6 +95,9 @@ public PartsModule( this.partTemplateService = partTemplateService; this.Get("/inventory/part-templates", _ => this.GetPartTemplates()); + this.Get("/inventory/part-templates/{id}", parameters => this.GetPartTemplate(parameters.id)); + this.Put("/inventory/part-templates/{id}", parameters => this.UpdatePartTemplate(parameters.id)); + this.Post("/inventory/part-templates", parameters => this.AddPartTemplate()); this.productAnalysisCodeService = productAnalysisCodeService; this.Get("inventory/product-analysis-codes", _ => this.GetProductAnalysisCodes()); @@ -226,6 +229,29 @@ private object GetPartCategories() .WithMediaRangeModel("text/html", ApplicationSettings.Get); } + private object AddPartTemplate() + { + this.RequiresAuthentication(); + var resource = this.Bind(); + var result = this.partTemplateService.Add(resource); + return this.Negotiate.WithStatusCode(HttpStatusCode.Created).WithModel(result); + } + + private object GetPartTemplate(string id) + { + var result = this.partTemplateService.GetById(id); + return this.Negotiate.WithModel(result) + .WithMediaRangeModel("text/html", ApplicationSettings.Get); + } + + private object UpdatePartTemplate(string id) + { + this.RequiresAuthentication(); + var resource = this.Bind(); + var result = this.partTemplateService.Update(id, resource); + return this.Negotiate.WithModel(result); + } + private object GetPartTemplates() { var result = this.partTemplateService.GetAll(); diff --git a/src/Service/ResponseProcessors/PartTemplateResponseProcessor.cs b/src/Service/ResponseProcessors/PartTemplateResponseProcessor.cs new file mode 100644 index 000000000..011096d16 --- /dev/null +++ b/src/Service/ResponseProcessors/PartTemplateResponseProcessor.cs @@ -0,0 +1,15 @@ +namespace Linn.Stores.Service.ResponseProcessors +{ + using System.Collections.Generic; + using Linn.Common.Facade; + using Linn.Common.Nancy.Facade; + using Linn.Stores.Domain.LinnApps.Parts; + + public class PartTemplateResponseProcessor : JsonResponseProcessor + { + public PartTemplateResponseProcessor(IResourceBuilder resourceBuilder) + : base(resourceBuilder, "linnapps-part-template", 1) + { + } + } +} diff --git a/tests/Integration/Service.Tests/PartsModuleSpecs/ContextBase.cs b/tests/Integration/Service.Tests/PartsModuleSpecs/ContextBase.cs index 8cb830ab6..0bb1290e9 100644 --- a/tests/Integration/Service.Tests/PartsModuleSpecs/ContextBase.cs +++ b/tests/Integration/Service.Tests/PartsModuleSpecs/ContextBase.cs @@ -179,6 +179,7 @@ public void EstablishContext() with.ResponseProcessor(); with.ResponseProcessor(); with.ResponseProcessor(); + with.ResponseProcessor(); with.ResponseProcessor(); with.ResponseProcessor(); with.ResponseProcessor(); diff --git a/tests/Integration/Service.Tests/PartsModuleSpecs/WhenAddingPartTemplate.cs b/tests/Integration/Service.Tests/PartsModuleSpecs/WhenAddingPartTemplate.cs new file mode 100644 index 000000000..ebf4d7a4f --- /dev/null +++ b/tests/Integration/Service.Tests/PartsModuleSpecs/WhenAddingPartTemplate.cs @@ -0,0 +1,92 @@ +namespace Linn.Stores.Service.Tests.PartsModuleSpecs +{ + using FluentAssertions; + + using Linn.Common.Facade; + using Linn.Stores.Domain.LinnApps.Parts; + using Linn.Stores.Resources.Parts; + + using Nancy; + using Nancy.Testing; + + using NSubstitute; + + using NUnit.Framework; + + public class WhenAddingPartTemplate : ContextBase + { + [SetUp] + public void SetUp() + { + var partTemplate = new PartTemplate + { + PartRoot = "LRPT", + Description = "A test for adding a part template", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "a part template being added as part of a test.", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + var partTemplateResource = new PartTemplateResource + { + Description = "A test for adding a part template", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "a part template being added as part of a test.", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + this.PartTemplateService.Add(Arg.Any()) + .Returns(new SuccessResult(partTemplate)); + + this.Response = this.Browser.Post( + "/inventory/part-templates", + with => + { + with.Header("Accept", "application/json"); + with.JsonBody(partTemplateResource); + }).Result; + } + + [Test] + public void ShouldReturnOk() + { + this.Response.StatusCode.Should().Be(HttpStatusCode.Created); + } + + [Test] + public void ShouldCallService() + { + this.PartTemplateService.Received().Add(Arg.Any()); + } + + [Test] + public void ShouldReturnResource() + { + var resource = this.Response.Body.DeserializeJson(); + resource.Description.Should().Be("A test for adding a part template"); + resource.NextNumber.Should().Be(32); + } + } +} diff --git a/tests/Integration/Service.Tests/PartsModuleSpecs/WhenGettingPartTemplateById .cs b/tests/Integration/Service.Tests/PartsModuleSpecs/WhenGettingPartTemplateById .cs new file mode 100644 index 000000000..7cda6d23d --- /dev/null +++ b/tests/Integration/Service.Tests/PartsModuleSpecs/WhenGettingPartTemplateById .cs @@ -0,0 +1,51 @@ +namespace Linn.Stores.Service.Tests.PartsModuleSpecs +{ + using FluentAssertions; + + using Linn.Common.Facade; + using Linn.Stores.Domain.LinnApps.Parts; + using Linn.Stores.Resources.Parts; + + using Nancy; + using Nancy.Testing; + + using NSubstitute; + + using NUnit.Framework; + + public class WhenGettingPartTemplatesById : ContextBase + { + private readonly string partRootString = "PARTTEMP"; + + [SetUp] + public void SetUp() + { + var partTemp = new PartTemplate { PartRoot = this.partRootString }; + + this.PartTemplateService.GetById(partTemp.PartRoot).Returns(new SuccessResult(partTemp)); + + this.Response = this.Browser.Get( + "/inventory/part-templates/PARTTEMP", + with => { with.Header("Accept", "application/json"); }).Result; + } + + [Test] + public void ShouldReturnOk() + { + this.Response.StatusCode.Should().Be(HttpStatusCode.OK); + } + + [Test] + public void ShouldCallService() + { + this.PartTemplateService.Received().GetById(this.partRootString); + } + + [Test] + public void ShouldReturnResource() + { + var resource = this.Response.Body.DeserializeJson(); + resource.PartRoot.Should().Be(this.partRootString); + } + } +} diff --git a/tests/Integration/Service.Tests/PartsModuleSpecs/WhenUpdatingPartTemplate.cs b/tests/Integration/Service.Tests/PartsModuleSpecs/WhenUpdatingPartTemplate.cs new file mode 100644 index 000000000..d26e311e2 --- /dev/null +++ b/tests/Integration/Service.Tests/PartsModuleSpecs/WhenUpdatingPartTemplate.cs @@ -0,0 +1,94 @@ +namespace Linn.Stores.Service.Tests.PartsModuleSpecs +{ + using FluentAssertions; + + using Linn.Common.Facade; + using Linn.Stores.Domain.LinnApps.Parts; + using Linn.Stores.Resources.Parts; + + using Nancy; + using Nancy.Testing; + + using NSubstitute; + + using NUnit.Framework; + + public class WhenUpdatingPartTemplate : ContextBase + { + private readonly string partId = "LRPT"; + + [SetUp] + public void SetUp() + { + var partTemplate = new PartTemplate + { + PartRoot = this.partId, + Description = "A test for updating a part template", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "a part template being updated as part of a test.", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + var partTemplateResource = new PartTemplateResource + { + Description = "A test for updating a part template", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "a part template being updated as part of a test.", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + this.PartTemplateService.Update(partTemplate.PartRoot, Arg.Any()) + .Returns(new SuccessResult(partTemplate)); + + this.Response = this.Browser.Put( + "/inventory/part-templates/LRPT", + with => + { + with.Header("Accept", "application/json"); + with.JsonBody(partTemplateResource); + }).Result; + } + + [Test] + public void ShouldReturnOk() + { + this.Response.StatusCode.Should().Be(HttpStatusCode.OK); + } + + [Test] + public void ShouldCallService() + { + this.PartTemplateService.Received().Update(this.partId, Arg.Any()); + } + + [Test] + public void ShouldReturnResource() + { + var resource = this.Response.Body.DeserializeJson(); + resource.Description.Should().Be("A test for updating a part template"); + resource.NextNumber.Should().Be(32); + } + } +} diff --git a/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/ContextBase.cs b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/ContextBase.cs new file mode 100644 index 000000000..9ac8cc753 --- /dev/null +++ b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/ContextBase.cs @@ -0,0 +1,27 @@ +namespace Linn.Stores.Facade.Tests.PartTemplateFacadeServiceTests +{ + using Linn.Common.Persistence; + using Linn.Stores.Domain.LinnApps.Parts; + using Linn.Stores.Facade.Services; + + using NSubstitute; + + using NUnit.Framework; + + public class ContextBase + { + protected PartTemplateService Sut { get; private set; } + + protected IRepository PartTemplateRepository { get; private set; } + + protected ITransactionManager TransactionManager { get; private set; } + + [SetUp] + public void SetUpContext() + { + this.PartTemplateRepository = Substitute.For>(); + this.TransactionManager = Substitute.For(); + this.Sut = new PartTemplateService(this.PartTemplateRepository, this.TransactionManager); + } + } +} diff --git a/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenAdding.cs b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenAdding.cs new file mode 100644 index 000000000..29df7e6e5 --- /dev/null +++ b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenAdding.cs @@ -0,0 +1,74 @@ +namespace Linn.Stores.Facade.Tests.PartTemplateFacadeServiceTests +{ + using FluentAssertions; + + using Linn.Common.Facade; + using Linn.Stores.Domain.LinnApps.Parts; + using Linn.Stores.Resources.Parts; + + using NSubstitute; + + using NUnit.Framework; + + public class WhenAdding : ContextBase + { + private PartTemplateResource resource; + + private IResult result; + + [SetUp] + public void SetUp() + { + this.resource = new PartTemplateResource + { + PartRoot = "LRPT", + Description = "A test for adding a part template", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "a part template being added as part of a test.", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + this.result = this.Sut.Add(this.resource); + } + + [Test] + public void ShouldAdd() + { + this.PartTemplateRepository.Received().Add(Arg.Any()); + } + + [Test] + public void ShouldReturnSuccess() + { + this.result.Should().BeOfType>(); + var dataResult = ((CreatedResult)this.result).Data; + dataResult.PartRoot.Should().Be("LRPT"); + dataResult.Description.Should().Be("A test for adding a part template"); + dataResult.HasDataSheet.Should().Be("N"); + dataResult.HasNumberSequence.Should().Be("Y"); + dataResult.NextNumber.Should().Be(32); + dataResult.AllowVariants.Should().Be("Y"); + dataResult.Variants.Should().Be("a part template being added as part of a test."); + dataResult.AccountingCompany.Should().Be("LINN RECORDS"); + dataResult.ProductCode.Should().Be("LINNPT"); + dataResult.StockControlled.Should().Be("Y"); + dataResult.LinnProduced.Should().Be("Y"); + dataResult.RmFg.Should().Be("L"); + dataResult.BomType.Should().Be("A"); + dataResult.AssemblyTechnology.Should().Be("RS"); + dataResult.AllowPartCreation.Should().Be("Y"); + dataResult.ParetoCode.Should().Be("J"); + } + } +} diff --git a/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenGettingById.cs b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenGettingById.cs new file mode 100644 index 000000000..71ec5a556 --- /dev/null +++ b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenGettingById.cs @@ -0,0 +1,69 @@ +namespace Linn.Stores.Facade.Tests.PartTemplateFacadeServiceTests +{ + using FluentAssertions; + + using Linn.Common.Facade; + using Linn.Stores.Domain.LinnApps.Parts; + + using NSubstitute; + + using NUnit.Framework; + + public class WhenGettingById : ContextBase + { + private readonly string partTempId = "LRPT"; + + private IResult result; + + [SetUp] + public void SetUp() + { + var partTemplate = new PartTemplate + { + PartRoot = this.partTempId, + Description = "A test for getting a part template by id", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "the id is retrieving the part template", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + this.PartTemplateRepository.FindById(Arg.Any()).Returns(partTemplate); + + this.result = this.Sut.GetById(this.partTempId); + } + + [Test] + public void ShouldReturnSuccess() + { + this.result.Should().BeOfType>(); + var dataResult = ((SuccessResult)this.result).Data; + dataResult.PartRoot.Should().Be(this.partTempId); + dataResult.Description.Should().Be("A test for getting a part template by id"); + dataResult.HasDataSheet.Should().Be("N"); + dataResult.HasNumberSequence.Should().Be("Y"); + dataResult.NextNumber.Should().Be(32); + dataResult.AllowVariants.Should().Be("Y"); + dataResult.Variants.Should().Be("the id is retrieving the part template"); + dataResult.AccountingCompany.Should().Be("LINN RECORDS"); + dataResult.ProductCode.Should().Be("LINNPT"); + dataResult.StockControlled.Should().Be("Y"); + dataResult.LinnProduced.Should().Be("Y"); + dataResult.RmFg.Should().Be("L"); + dataResult.BomType.Should().Be("A"); + dataResult.AssemblyTechnology.Should().Be("RS"); + dataResult.AllowPartCreation.Should().Be("Y"); + dataResult.ParetoCode.Should().Be("J"); + } + } +} diff --git a/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenUpdating.cs b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenUpdating.cs new file mode 100644 index 000000000..1103956de --- /dev/null +++ b/tests/Unit/Facade.Tests/PartTemplateFacadeServiceTests/WhenUpdating.cs @@ -0,0 +1,100 @@ +namespace Linn.Stores.Facade.Tests.PartTemplateFacadeServiceTests +{ + using FluentAssertions; + + using Linn.Common.Facade; + using Linn.Stores.Domain.LinnApps.Parts; + using Linn.Stores.Resources.Parts; + + using NSubstitute; + + using NUnit.Framework; + + public class WhenUpdating : ContextBase + { + private readonly string partTempId = "LRPT"; + + private PartTemplateResource resource; + + private IResult result; + + [SetUp] + public void SetUp() + { + var partTemplate = new PartTemplate + { + PartRoot = "LRPT", + Description = "A test for getting a part template by id", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "the id is retrieving the part template", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + this.resource = new PartTemplateResource + { + PartRoot = "LRPT", + Description = "A test for getting a part template by id", + HasDataSheet = "N", + HasNumberSequence = "Y", + NextNumber = 32, + AllowVariants = "Y", + Variants = "the id is retrieving the part template", + AccountingCompany = "LINN RECORDS", + ProductCode = "LINNPT", + StockControlled = "Y", + LinnProduced = "Y", + RmFg = "L", + BomType = "A", + AssemblyTechnology = "RS", + AllowPartCreation = "Y", + ParetoCode = "J" + }; + + this.result = this.Sut.Add(this.resource); + + this.PartTemplateRepository.FindById(this.partTempId).Returns(partTemplate); + + this.result = this.Sut.Update(this.resource.PartRoot, this.resource); + } + + [Test] + public void ShouldGet() + { + this.PartTemplateRepository.Received().FindById(this.partTempId); + } + + [Test] + public void ShouldReturnSuccess() + { + this.result.Should().BeOfType>(); + var dataResult = ((SuccessResult)this.result).Data; + dataResult.PartRoot.Should().Be(this.partTempId); + dataResult.Description.Should().Be("A test for getting a part template by id"); + dataResult.HasDataSheet.Should().Be("N"); + dataResult.HasNumberSequence.Should().Be("Y"); + dataResult.NextNumber.Should().Be(32); + dataResult.AllowVariants.Should().Be("Y"); + dataResult.Variants.Should().Be("the id is retrieving the part template"); + dataResult.AccountingCompany.Should().Be("LINN RECORDS"); + dataResult.ProductCode.Should().Be("LINNPT"); + dataResult.StockControlled.Should().Be("Y"); + dataResult.LinnProduced.Should().Be("Y"); + dataResult.RmFg.Should().Be("L"); + dataResult.BomType.Should().Be("A"); + dataResult.AssemblyTechnology.Should().Be("RS"); + dataResult.AllowPartCreation.Should().Be("Y"); + dataResult.ParetoCode.Should().Be("J"); + } + } +}