public async Task ChangeOwner_WhenUserAndCostAreValid_ShouldSaveHistoricalOwner() { // Arrange var oldOwnerId = Guid.NewGuid(); var oldOwner = new CostUser { Id = oldOwnerId }; var newOwnerId = Guid.NewGuid(); var newOwner = new CostUser { Id = newOwnerId }; var cost = new Cost { Owner = oldOwner, OwnerId = oldOwner.Id, Id = Guid.NewGuid() }; cost.CostOwners = new List <CostOwner>(); // Act var result = await CostService.ChangeOwner(User, cost, newOwner); // Assert result.CostOwners.Should().HaveCount(1); Assert.AreEqual(result.CostOwners[0].UserId, oldOwner.Id); Assert.AreEqual(result.CostOwners[0].CostId, cost.Id); }
public async Task InsertCost() { //Setup var adCostNumber = "adCostNumber"; var templateId = Guid.NewGuid(); var requestModel = CreateCostModel(templateId); var costModel = new CostBuilderModel { Stages = new[] { new CostStageModel { Revisions = new [] { new CostStageRevisionModel { SupportingDocuments = new List <SupportingDocumentModel>() } } } } }; var costUser = new CostUser { Id = User.Id, Agency = new Agency { Id = User.AgencyId, } }; var responseMock = new Mock <ICreateCostResponse>(); responseMock.SetupGet(f => f.Cost).Returns(costModel); PgUserServiceMock.Setup(a => a.GrantUsersAccess(It.IsAny <Cost>(), It.IsAny <CreateCostModel>())).Returns(Task.CompletedTask); CostBuilderMock.Setup(e => e.CreateCost(It.IsAny <CostUser>(), It.IsAny <CreateCostModel>())) .ReturnsAsync(responseMock.Object); EFContext.Project.Add(new Project { Id = Guid.NewGuid(), AdCostNumber = adCostNumber }); EFContext.CostUser.Add(costUser); await EFContext.SaveChangesAsync(); PermissionService.Setup(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())) .ReturnsAsync(new[] { Guid.NewGuid().ToString() }); //Act await CostService.CreateCost(User, requestModel); //Assert CostBuilderMock.Verify(e => e.CreateCost(costUser, requestModel), Times.Once); EFContext.Cost.Should().HaveCount(1); EFContext.NotificationSubscriber.Should().HaveCount(0); Mapper.Verify(m => m.Map <CostModel>(It.Is <Cost>(c => c != null && c.Status == CostStageRevisionStatus.Draft))); }
public void ChangeOwner_WhenCostOwnerIsNull_ShouldThrowException() { // Arrange var cost = new Cost(); CostUser owner = null; // Act // Assert CostService.Awaiting(s => s.ChangeOwner(User, cost, owner)).ShouldThrow <ArgumentNullException>(); }
public async Task GrandEditPermissionToOwner() { //Setup var adCostNumber = "adCostNumber"; var templateId = Guid.NewGuid(); var requestModel = CreateCostModel(templateId); var costModel = new CostBuilderModel { Stages = new[] { new CostStageModel { Revisions = new [] { new CostStageRevisionModel { SupportingDocuments = new List <SupportingDocumentModel>() } } } } }; var costUser = new CostUser { Id = User.Id, Agency = new Agency { Id = User.AgencyId, } }; var responseMock = new Mock <ICreateCostResponse>(); responseMock.SetupGet(f => f.Cost).Returns(costModel); PgUserServiceMock.Setup(a => a.GrantUsersAccess(It.IsAny <Cost>(), It.IsAny <CreateCostModel>())).Returns(Task.CompletedTask); CostBuilderMock.Setup(e => e.CreateCost(It.IsAny <CostUser>(), It.IsAny <CreateCostModel>())) .ReturnsAsync(responseMock.Object); EFContext.Project.Add(new Project { Id = Guid.NewGuid(), AdCostNumber = adCostNumber }); EFContext.CostUser.Add(costUser); await EFContext.SaveChangesAsync(); PermissionService.Setup(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())) .ReturnsAsync(new[] { Guid.NewGuid().ToString() }); //Act await CostService.CreateCost(User, requestModel); //Assert CostStageRevisionPermissionServiceMock.Verify(p => p.GrantCostPermission(It.IsAny <Guid>(), Roles.CostEditor, It.Is <IEnumerable <CostUser> >(c => c.Any(i => i == costUser)), BuType.Pg, It.IsAny <Guid?>(), true), Times.Once); }
public void ChangeOwner_WhenUserIdentityIsNull_ShouldThrowException() { // Arrange Cost cost = new Cost { Owner = new CostUser() }; CostUser owner = new CostUser(); // Act // Assert CostService.Awaiting(s => s.ChangeOwner(null, cost, owner)).ShouldThrow <ArgumentNullException>(); }
public async Task Not_return_deleted_costs() { // Arrange var costId = Guid.NewGuid(); var cost = new Cost { Id = costId, Deleted = true }; var userId = Guid.NewGuid(); var user = new UserIdentity { Id = userId }; ActionBuilderMock.Setup(a => a.GetActions(It.IsAny <IEnumerable <Guid> >(), user)) .ReturnsAsync(new Dictionary <Guid, CostActionsModel> { { costId, new CostActionsModel(cost, new Dictionary <string, ActionModel>()) } } ); EFContext.Cost.Add(cost); await EFContext.SaveChangesAsync(); var costQuery = new CostQuery(); SearchServiceMock.Setup(ss => ss.SearchCosts(costQuery, user.Id)).ReturnsAsync(( new[] { new CostSearchItem { Id = costId.ToString(), CreatedBy = userId.ToString() } }, 1) ); // Act var searchResult = await CostService.Search(costQuery, user); // Assert searchResult.Count.Should().Be(0); searchResult.Costs.Count.Should().Be(0); }
public async Task ChangeOwner_WhenUserAndCostAreValid_ShouldChageOwnerOfTheCost() { // Arrange var cost = new Cost { Owner = new CostUser(), CostOwners = new List <CostOwner>() }; var ownerId = Guid.NewGuid(); var owner = new CostUser { Id = ownerId }; // Act var result = await CostService.ChangeOwner(User, cost, owner); // Assert result.Owner.Should().Be(owner); result.OwnerId.Should().Be(ownerId); }
public async Task GetExchangeRatesOfCurrenciesInCost_Should_Include_DefaultCurrency() { //Setup await CreateExchangeRate(); var paymentCurrency = EFContext.Currency.First(c => c.Code == "AUD"); var costLineItemCurrency = EFContext.Currency.First(c => c.Code == "CAD"); var costId = await CreateCostTest(paymentCurrency, costLineItemCurrency); var cost = EFContext.Cost.First(c => c.Id == costId); //Act var lstExchangeRates = await CostService.GetExchangeRatesOfCurrenciesInCost(cost); //Assert lstExchangeRates.Should().Contain(c => c.FromCurrency == paymentCurrency.Id); lstExchangeRates.Should().Contain(c => c.FromCurrency == costLineItemCurrency.Id); }