public async Task CreateDepartment_DepartmentAlreadyExist_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newDepartment = new NodeDto { Id = 2, Name = "Kitchen", Type = "Department", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.CreateNodeAsync(newDepartment); var expectResult = new ServiceResult($"Department with name: {newDepartment.Name} - already exist."); var actualListOfNodes = await _treeService.GetTreeAsync(); Assert.Equal(6, actualListOfNodes.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task CreateBusiness_IsSuccessful() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newBusiness = new NodeDto { Id = 2, Name = "Internet", Type = "Business", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var result = await _treeService.CreateNodeAsync(newBusiness); var actualBusiness = (await _treeService.GetTreeAsync())[3]; Assert.True(result.Succeeded); Assert.Equal(newBusiness.Id, actualBusiness.Id); Assert.Equal(newBusiness.Name, actualBusiness.Name); Assert.Equal(newBusiness.ParentId, actualBusiness.ParentId); Assert.Equal(newBusiness.Type, actualBusiness.Type); }
public async Task CreateCountry_OrganizationNotFound_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newCountry = new NodeDto { Id = 2, Name = "Canada", Type = "Country", Properties = new NodePropertiesDto { Code = "1234" }, ParentId = 2 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.CreateNodeAsync(newCountry); var expectResult = new ServiceResult($"Organization with id: {newCountry.ParentId} - not found."); var actualListOfNodes = await _treeService.GetTreeAsync(); Assert.Equal(6, actualListOfNodes.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task CreateDepartment_WrongNodeType_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newDepartment = new NodeDto { Id = 2, Name = "Service", Type = "Home", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.CreateNodeAsync(newDepartment); var expectResult = new ServiceResult($"Not found such type as: {newDepartment.Type}"); var actualListOfNodes = await _treeService.GetTreeAsync(); Assert.Equal(6, actualListOfNodes.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task CreateFamily_BusinessNotFound_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newFamily = new NodeDto { Id = 2, Name = "Fast food", Type = "Family", ParentId = 2 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.CreateNodeAsync(newFamily); var expectResult = new ServiceResult($"Business with id: {newFamily.ParentId} - not found."); var actualListOfNodes = await _treeService.GetTreeAsync(); Assert.Equal(6, actualListOfNodes.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task CreateOffering_IsSuccessful() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOffering = new NodeDto { Id = 2, Name = "Pizza", Type = "Offering", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var result = await _treeService.CreateNodeAsync(newOffering); var actualOffering = (await _treeService.GetTreeAsync())[5]; Assert.True(result.Succeeded); Assert.Equal(newOffering.Id, actualOffering.Id); Assert.Equal(newOffering.Name, actualOffering.Name); Assert.Equal(newOffering.ParentId, actualOffering.ParentId); Assert.Equal(newOffering.Type, actualOffering.Type); }
public async Task CreateDepartment_IsSuccessful() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newDepartment = new NodeDto { Id = 2, Name = "Service", Type = "Department", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var result = await _treeService.CreateNodeAsync(newDepartment); var actualDepartment = (await _treeService.GetTreeAsync())[6]; Assert.True(result.Succeeded); Assert.Equal(newDepartment.Id, actualDepartment.Id); Assert.Equal(newDepartment.Name, actualDepartment.Name); Assert.Equal(newDepartment.ParentId, actualDepartment.ParentId); Assert.Equal(newDepartment.Type, actualDepartment.Type); }
public async Task CreateCountry_CountryAlreadyExist_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newCountry = new NodeDto { Id = 2, Name = "USA", Type = "Country", Properties = new NodePropertiesDto { Code = "1111" }, ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.CreateNodeAsync(newCountry); var expectResult = new ServiceResult($"Country with code: {newCountry.Properties.Code} - already exist."); var actualListOfNodes = await _treeService.GetTreeAsync(); Assert.Equal(6, actualListOfNodes.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task CreateFamily_IsSuccessful() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newFamily = new NodeDto { Id = 2, Name = "Fast food", Type = "Family", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var result = await _treeService.CreateNodeAsync(newFamily); var actualFamily = (await _treeService.GetTreeAsync())[4]; Assert.True(result.Succeeded); Assert.Equal(newFamily.Id, actualFamily.Id); Assert.Equal(newFamily.Name, actualFamily.Name); Assert.Equal(newFamily.ParentId, actualFamily.ParentId); Assert.Equal(newFamily.Type, actualFamily.Type); }
public async Task CreateDepartment_OfferingNotFound_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newDepartment = new NodeDto { Id = 2, Name = "Service", Type = "Department", ParentId = 2 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.CreateNodeAsync(newDepartment); var expectResult = new ServiceResult($"Offering with id: {newDepartment.ParentId} - not found."); var actualListOfNodes = await _treeService.GetTreeAsync(); Assert.Equal(6, actualListOfNodes.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task CreateOrganization_IsSuccessful() { _treeService = GetTreeService(); var newOrganization = new NodeDto { Id = 1, Name = "Organization1", Type = "Organization", Properties = new NodePropertiesDto { Code = "1234", OrganizationType = OrganizationType.LimitedLiabilityCompany, OrganizationOwner = "Mr. Bin" }, ParentId = 0 }; var result = await _treeService.CreateNodeAsync(newOrganization); var actualOrganization = (await _treeService.GetTreeAsync())[0]; Assert.True(result.Succeeded); Assert.Equal(newOrganization.Id, actualOrganization.Id); Assert.Equal(newOrganization.Name, actualOrganization.Name); Assert.Equal(newOrganization.ParentId, actualOrganization.ParentId); Assert.Equal(newOrganization.Type, actualOrganization.Type); Assert.Equal(newOrganization.Properties.Code, actualOrganization.Properties.Code); Assert.Equal(newOrganization.Properties.OrganizationType, actualOrganization.Properties.OrganizationType); Assert.Equal(newOrganization.Properties.OrganizationOwner, actualOrganization.Properties.OrganizationOwner); }
public async Task CreateOrganization_WrongNodeType_IsFailed() { _treeService = GetTreeService(); var newOrganization = new NodeDto { Id = 1, Name = "Organization1", Type = "Home", Properties = new NodePropertiesDto { Code = "1234", OrganizationType = OrganizationType.LimitedLiabilityCompany, OrganizationOwner = "Mr. Bin" }, ParentId = 0 }; var actualResult = await _treeService.CreateNodeAsync(newOrganization); var expectResult = new ServiceResult($"Not found such type as: {newOrganization.Type}"); var actualListOfNodes = await _treeService.GetTreeAsync(); Assert.Equal(0, actualListOfNodes.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task DeleteNode_WrongNodeType_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var nodeToDelete = new NodeDto { Id = 1, Type = "Home" }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.DeleteNodeAsync(nodeToDelete); var expectResult = new ServiceResult($"Not found such type as: {nodeToDelete.Type}"); var actualTree = await _treeService.GetTreeAsync(); Assert.Equal(12, actualTree.Count); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateOrganization_WrongNodeType_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOrganization = new NodeDto { Id = 1, Name = "newOrganization1", Type = "Home", Properties = new NodePropertiesDto { Code = "3548", OrganizationType = OrganizationType.LimitedLiabilityCompany, OrganizationOwner = "Mr. Bin" }, ParentId = 0 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newOrganization); var expectResult = new ServiceResult($"Not found such type as: {newOrganization.Type}"); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateOrganization_OrganizationAlreadyExist_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOrganization = new NodeDto { Id = 1, Name = "Organization2", Type = "Organization", Properties = new NodePropertiesDto { Code = "5678", OrganizationType = OrganizationType.GeneralPartnership, OrganizationOwner = "Mr. Paul" }, ParentId = 0 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newOrganization); var expectResult = new ServiceResult($"Organization with code: {newOrganization.Properties.Code} - already exist."); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateOffering_OfferingNotFound_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOffering = new NodeDto { Id = 0, Name = "Pizza", Type = "Offering", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newOffering); var expectResult = new ServiceResult($"Offering with id: {newOffering.Id} - not found."); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateBusiness_BusinessNotFound_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newBusiness = new NodeDto { Id = 0, Name = "Internet", Type = "Business", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newBusiness); var expectResult = new ServiceResult($"Business with id: {newBusiness.Id} - not found."); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateOrganization_OrganizationNotFound_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOrganization = new NodeDto { Id = 0, Name = "newOrganization1", Type = "Organization", Properties = new NodePropertiesDto { Code = "1234", OrganizationType = OrganizationType.GeneralPartnership, OrganizationOwner = "Mr. Lu" }, ParentId = 0 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newOrganization); var expectResult = new ServiceResult($"Organization with id: {newOrganization.Id} - not found."); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateOffering_WrongNodeType_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOffering = new NodeDto { Id = 1, Name = "Pizza", Type = "Home", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newOffering); var expectResult = new ServiceResult($"Not found such type as: {newOffering.Type}"); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateCountry_WrongNodeType_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newCountry = new NodeDto { Id = 1, Name = "Canada", Type = "Home", Properties = new NodePropertiesDto { Code = "1234" }, ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newCountry); var expectResult = new ServiceResult($"Not found such type as: {newCountry.Type}"); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task UpdateFamily_FamilyAlreadyExist_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newFamily = new NodeDto { Id = 1, Name = "Cinema", Type = "Family", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newFamily); var expectResult = new ServiceResult($"Family with name: {newFamily.Name} - already exist."); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task DeleteBusiness_IsSuccessful() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var businessToDelete = new NodeDto { Id = 1, Type = "Business" }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var result = await _treeService.DeleteNodeAsync(businessToDelete); var actualTree = await _treeService.GetTreeAsync(); Assert.True(result.Succeeded); Assert.Equal(5, actualTree.Count); }
public async Task UpdateOffering_OfferingAlreadyExist_IsFailed() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOffering = new NodeDto { Id = 1, Name = "Multfilms", Type = "Offering", ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var actualResult = await _treeService.UpdateNodeAsync(newOffering); var expectResult = new ServiceResult($"Offering with name: {newOffering.Name} - already exist."); Assert.Equal(expectResult.Succeeded, actualResult.Succeeded); Assert.Equal(expectResult.Error, actualResult.Error); }
public async Task CreateCountry_IsSuccessful() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newCountry = new NodeDto { Id = 2, Name = "Canada", Type = "Country", Properties = new NodePropertiesDto { Code = "1234" }, ParentId = 1 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var result = await _treeService.CreateNodeAsync(newCountry); var actualCountry = (await _treeService.GetTreeAsync())[2]; Assert.True(result.Succeeded); Assert.Equal(newCountry.Id, actualCountry.Id); Assert.Equal(newCountry.Name, actualCountry.Name); Assert.Equal(newCountry.ParentId, actualCountry.ParentId); Assert.Equal(newCountry.Type, actualCountry.Type); Assert.Equal(newCountry.Properties.Code, actualCountry.Properties.Code); }
public async Task <ActionResult> CreateNode([FromBody] NodeToCreateModel model) { if (!ModelState.IsValid) { return(BadRequest(new ResponseModel(400, "Invalid value was entered! Please, redisplay form."))); } var nodeDto = _mapper.Map <NodeDto>(model); var result = await _treeService.CreateNodeAsync(nodeDto); return(result.Succeeded ? Ok(new ResponseModel(200, "Completed.", "Node created.")) : (ActionResult)BadRequest(new ResponseModel(400, "Failed.", result.Error))); }
public async Task GetTreeAsync_IsSuccessful() { _treeService = GetTreeService(); var excpectResult = GetNodes(); foreach (var node in excpectResult) { await _treeService.CreateNodeAsync(node); } var actualResult = await _treeService.GetTreeAsync(); for (int i = 0; i < excpectResult.Count; i++) { switch (excpectResult[i].Type) { case "Organization": Assert.Equal(excpectResult[i].Id, actualResult[i].Id); Assert.Equal(excpectResult[i].Name, actualResult[i].Name); Assert.Equal(excpectResult[i].ParentId, actualResult[i].ParentId); Assert.Equal(excpectResult[i].Type, actualResult[i].Type); Assert.Equal(excpectResult[i].Properties.Code, actualResult[i].Properties.Code); Assert.Equal(excpectResult[i].Properties.OrganizationType, actualResult[i].Properties.OrganizationType); Assert.Equal(excpectResult[i].Properties.OrganizationOwner, actualResult[i].Properties.OrganizationOwner); return; case "Country": Assert.Equal(excpectResult[i].Id, actualResult[i].Id); Assert.Equal(excpectResult[i].Name, actualResult[i].Name); Assert.Equal(excpectResult[i].ParentId, actualResult[i].ParentId); Assert.Equal(excpectResult[i].Type, actualResult[i].Type); Assert.Equal(excpectResult[i].Properties.Code, actualResult[i].Properties.Code); return; default: Assert.Equal(excpectResult[i].Id, actualResult[i].Id); Assert.Equal(excpectResult[i].Name, actualResult[i].Name); Assert.Equal(excpectResult[i].ParentId, actualResult[i].ParentId); Assert.Equal(excpectResult[i].Type, actualResult[i].Type); return; } } }
public async Task UpdateOrganization_IsSuccessful() { _treeService = GetTreeService(); var dataToSetupDB = GetNodes(); var newOrganization = new NodeDto { Id = 1, Name = "newOrganization", Type = "Organization", Properties = new NodePropertiesDto { Code = "1234", OrganizationType = OrganizationType.IncorporatedCompany, OrganizationOwner = "Mr. Paul" }, ParentId = 0 }; foreach (var node in dataToSetupDB) { var dbSetupResult = await _treeService.CreateNodeAsync(node); Assert.True(dbSetupResult.Succeeded); } var result = await _treeService.UpdateNodeAsync(newOrganization); var actualOrganization = (await _treeService.GetTreeAsync())[0]; Assert.True(result.Succeeded); Assert.Equal(newOrganization.Id, actualOrganization.Id); Assert.Equal(newOrganization.Name, actualOrganization.Name); Assert.Equal(newOrganization.ParentId, actualOrganization.ParentId); Assert.Equal(newOrganization.Type, actualOrganization.Type); Assert.Equal(newOrganization.Properties.Code, actualOrganization.Properties.Code); Assert.Equal(newOrganization.Properties.OrganizationType, actualOrganization.Properties.OrganizationType); Assert.Equal(newOrganization.Properties.OrganizationOwner, actualOrganization.Properties.OrganizationOwner); }