Exemple #1
0
        public async Task Get_ShouldReturnBrandDetails()
        {
            // Arrange
            var brandUuid    = Guid.NewGuid();
            var buyerAccount = new BuyerAccount {
                BuyerAccountId = 1
            };
            var advertiser = new Advertiser {
                BuyerAccountId = buyerAccount.BuyerAccountId, BuyerAccount = buyerAccount, AdvertiserId = 1
            };
            var advertiserProduct = new AdvertiserProduct {
                AdvertiserId = advertiser.AdvertiserId, ProductName = "product name"
            };

            Mock.Mock <IBrandService>().Setup(x => x.GetBrand(brandUuid))
            .Returns(Task.FromResult(advertiserProduct));

            // Act
            var retVal = await Controller.Get(brandUuid);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkNegotiatedContentResult <BrandViewModel> >());
            var content = ((OkNegotiatedContentResult <BrandViewModel>)retVal).Content;

            Assert.That(content, Is.Not.Null);
            Assert.That(content.BrandName, Is.EqualTo(advertiserProduct.ProductName));
        }
Exemple #2
0
        public async Task Get_ShouldReturnListOfBrands()
        {
            // Arrange
            var userId = Guid.NewGuid();
            var model  = new BrandQueryViewModel {
                UserId = userId
            };
            var buyerAccount = new BuyerAccount {
                BuyerAccountId = 1
            };
            var advertiser = new Advertiser {
                BuyerAccountId = buyerAccount.BuyerAccountId, BuyerAccount = buyerAccount, AdvertiserId = 1
            };
            var advertiserProduct1 = new AdvertiserProduct {
                AdvertiserId = advertiser.AdvertiserId, ProductName = "product a"
            };
            var advertiserProduct2 = new AdvertiserProduct {
                AdvertiserId = advertiser.AdvertiserId, ProductName = "product b"
            };
            var advertiserProducts = new List <AdvertiserProduct> {
                advertiserProduct1, advertiserProduct2
            };

            Mock.Mock <IBrandService>().Setup(x => x.GetBrands(It.IsAny <BrandQueryOptions>()))
            .Returns(advertiserProducts.ToAsyncEnumerable());

            // Act
            var retVal = await Controller.Get(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal.TotalItemCount, Is.EqualTo(2));
        }
Exemple #3
0
        public async Task Get_ShouldReturnAdvertiserDetails()
        {
            // Arrange
            var advertiserUuid = Guid.NewGuid();
            var buyerAccount1  = new BuyerAccount {
                BuyerAccountId = 1
            };
            var advertiser = new Advertiser {
                BuyerAccountId = buyerAccount1.BuyerAccountId, BuyerAccount = buyerAccount1, AdvertiserName = "WJsHome"
            };

            Mock.Mock <IAdvertiserService>().Setup(x => x.GetAdvertiser(advertiserUuid))
            .Returns(Task.FromResult(advertiser));

            // Act
            var retVal = await Controller.Get(advertiserUuid);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkNegotiatedContentResult <AdvertiserViewModel> >());
            var content = ((OkNegotiatedContentResult <AdvertiserViewModel>)retVal).Content;

            Assert.That(content, Is.Not.Null);
            Assert.That(content.AdvertiserName, Is.EqualTo(advertiser.AdvertiserName));
        }
        public void GetAdvertisers_ShouldReturnAllAdvertisers_WhenNoOptions()
        {
            // Arrange
            var emptyOptions = new AdvertiserQueryOptions();

            var buyerAccount1 = new BuyerAccount {
                BuyerAccountId = 1
            };
            var buyerAccount2 = new BuyerAccount {
                BuyerAccountId = 2
            };
            var advertisers = new List <Advertiser>
            {
                new Advertiser {
                    BuyerAccountId = buyerAccount1.BuyerAccountId, BuyerAccount = buyerAccount1
                },
                new Advertiser {
                    BuyerAccountId = buyerAccount1.BuyerAccountId, BuyerAccount = buyerAccount1
                },
                new Advertiser {
                    BuyerAccountId = buyerAccount2.BuyerAccountId, BuyerAccount = buyerAccount2
                }
            };

            MockUnitOfWorkRepository <Advertiser>().Setup(x => x.Queryable())
            .Returns(advertisers.ToAsyncEnumerable());

            // Act
            var retVal = Mock.Create <AdvertiserService>().GetAdvertisers(emptyOptions).ToList();

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal.Count, Is.EqualTo(3));
        }
Exemple #5
0
        public async Task Get_ShouldReturnSegmentDetails()
        {
            // Arrange
            var segmentId    = 1;
            var buyerAccount = new BuyerAccount {
                BuyerAccountId = 1
            };
            var advertiser = new Advertiser {
                BuyerAccountId = buyerAccount.BuyerAccountId, BuyerAccount = buyerAccount, AdvertiserId = 1
            };
            var segment = new Segment {
                AdvertiserId = advertiser.AdvertiserId, SegmentName = "segment name"
            };

            Mock.Mock <ISegmentService>().Setup(x => x.GetSegment(segmentId))
            .Returns(Task.FromResult(segment));

            // Act
            var retVal = await Controller.Get(segmentId);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkNegotiatedContentResult <SegmentViewModel> >());
            var content = ((OkNegotiatedContentResult <SegmentViewModel>)retVal).Content;

            Assert.That(content, Is.Not.Null);
            Assert.That(content.SegmentName, Is.EqualTo(segment.SegmentName));
        }
 public async Task CreateAccount(BuyerAccount buyerAccount, User owner)
 {
     buyerAccount.BuyerAccountUuid          = IdentityValue.GenerateNewId();
     buyerAccount.CommercialContactUserId   = owner.UserId;
     buyerAccount.TermsConditionsAgreedDate = _clock.UtcNow;
     buyerAccount.UtcCreatedDateTime        = _clock.UtcNow;
     buyerAccount.UserBuyerRoles.Add(new UserBuyerRole
     {
         ObjectState    = ObjectState.Added,
         UserId         = owner.UserId,
         BuyerAccountId = buyerAccount.BuyerAccountId,
         RoleName       = StandardRole.Administrator,
         IsAccepted     = true,
         CostView       = (int)CostViewEnum.ClientCost
     });
     _buyerAccountRepositoryAsync.Insert(buyerAccount);
     await _brandscreenContext.SaveChangesAsync();
 }
        public static AccountStatusEnum GetStatus(this BuyerAccount buyerAccount)
        {
            if (!buyerAccount.UtcStatusChangedDateTime.HasValue)
            {
                return(AccountStatusEnum.Pending);
            }

            AccountStatusEnum status;

            if (buyerAccount.IsApproved)
            {
                status = buyerAccount.IsActive ? AccountStatusEnum.Activated : AccountStatusEnum.Suspended;
            }
            else
            {
                status = AccountStatusEnum.Rejected;
            }
            return(status);
        }
        public async Task <IdentityResult> RegisterUser(User user, string password, BuyerAccount buyerAccount)
        {
            // try to create user in ASP.NET IDENTITY
            var applicationUser = new ApplicationUser
            {
                ApplicationId  = _applicationUserManager.GetApplicationId(),
                Email          = user.Email,
                UserName       = user.Email,
                IsApproved     = true,
                EmailConfirmed = true, // set to confirmed
            };
            var result = await _applicationUserManager.CreateAsync(applicationUser, password);

            if (!result.Succeeded)
            {
                return(result);
            }

            // create user
            user.UserId     = Guid.Parse(applicationUser.Id);
            user.TimeSpanId = (int)TimeSpanEnum.LastMonth;
            user.TermsAndConditionsAgreedDate = DateTime.UtcNow;
            _userRepositoryAsync.Insert(user);

            // create buyer account for the user: context save changes will be called
            await _accountService.CreateAccount(buyerAccount, user);

            // msmq: new user creation email
            _serviceBus.Send(new UserMessage
            {
                Action           = CrudAction.Created,
                BuyerAccountId   = buyerAccount.BuyerAccountId,
                UserId           = user.UserId,
                NewPassword      = password,
                InitiatingUserId = user.UserId,
                BuyerAccountUuid = buyerAccount.BuyerAccountUuid
            }, noThrowServiceNotAvailableException: true);

            return(result);
        }
Exemple #9
0
        public async Task PatchTerms_ShouldReturnOk()
        {
            // Arrange
            var buyerAccountUuid = Guid.NewGuid();
            var account          = new BuyerAccount {
                BuyerAccountUuid = buyerAccountUuid, CompanyName = "Brandscreen"
            };
            var model = new AccountTermsPatchViewModel {
                CreditLimit = 1000
            };

            Mock.Mock <IAccountService>().Setup(x => x.GetAccount(buyerAccountUuid))
            .ReturnsAsync(account);

            // Act
            var retVal = await Controller.PatchTerms(buyerAccountUuid, model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <IAccountService>().Verify(x => x.UpdateAccount(It.Is <BuyerAccount>(buyerAccount => buyerAccount.CreditLimit == model.CreditLimit)), Times.Once);
        }
Exemple #10
0
        public async Task Get_ShouldReturnAccountDetails()
        {
            // Arrange
            var buyerAccountUuid = Guid.NewGuid();
            var account          = new BuyerAccount {
                BuyerAccountUuid = buyerAccountUuid, CompanyName = "Brandscreen"
            };

            Mock.Mock <IAccountService>().Setup(x => x.GetAccount(buyerAccountUuid))
            .Returns(Task.FromResult(account));

            // Act
            var retVal = await Controller.Get(buyerAccountUuid);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkNegotiatedContentResult <AccountViewModel> >());
            var content = ((OkNegotiatedContentResult <AccountViewModel>)retVal).Content;

            Assert.That(content, Is.Not.Null);
            Assert.That(content.CompanyName, Is.EqualTo(account.CompanyName));
        }
        public async Task Get_ShouldReturnUserList()
        {
            // Arrange
            var buyerAccountId   = 1;
            var buyerAccountUuid = Guid.NewGuid();
            var buyerAccount     = new BuyerAccount {
                BuyerAccountId = buyerAccountId, BuyerAccountUuid = buyerAccountUuid
            };
            var model = new UserQueryViewModel {
                BuyerAccountUuid = buyerAccountUuid
            };
            var user = new User {
                UserId = Guid.NewGuid()
            };
            var userBuyerRole = new UserBuyerRole {
                UserId = user.UserId, BuyerAccountId = buyerAccountId, RoleName = "Role"
            };

            user.UserBuyerRoles.Add(userBuyerRole);
            var users = new List <User> {
                user
            };

            Mock.Mock <IAccountService>().Setup(x => x.GetAccount(buyerAccountUuid)).Returns(Task.FromResult(buyerAccount));
            Mock.Mock <IUserService>().Setup(x => x.GetUsers(It.IsAny <UserQueryOptions>())).Returns(users.ToAsyncEnumerable());

            // Act
            var retVal = await Controller.Get(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkNegotiatedContentResult <PagedListViewModel <UserListViewModel> > >());
            var content = ((OkNegotiatedContentResult <PagedListViewModel <UserListViewModel> >)retVal).Content;

            Assert.That(content.TotalItemCount, Is.EqualTo(1));
            Assert.That(content.Data.ElementAt(0).UserId, Is.EqualTo(user.UserId));
        }
Exemple #12
0
        public async Task Get_ShouldReturnListOfAdvertisers()
        {
            // Arrange
            var userId = Guid.NewGuid();
            var model  = new AdvertiserQueryViewModel {
                UserId = userId
            };
            var buyerAccount1 = new BuyerAccount {
                BuyerAccountId = 1
            };
            var buyerAccount2 = new BuyerAccount {
                BuyerAccountId = 2
            };
            var advertisers = new List <Advertiser>
            {
                new Advertiser {
                    BuyerAccountId = buyerAccount1.BuyerAccountId, BuyerAccount = buyerAccount1
                },
                new Advertiser {
                    BuyerAccountId = buyerAccount1.BuyerAccountId, BuyerAccount = buyerAccount1
                },
                new Advertiser {
                    BuyerAccountId = buyerAccount2.BuyerAccountId, BuyerAccount = buyerAccount2
                }
            };

            Mock.Mock <IAdvertiserService>().Setup(x => x.GetAdvertisers(It.IsAny <AdvertiserQueryOptions>()))
            .Returns(advertisers.ToAsyncEnumerable());

            // Act
            var retVal = await Controller.Get(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal.TotalItemCount, Is.EqualTo(3));
        }
Exemple #13
0
        public async Task Get_ShouldReturnListOfAccounts()
        {
            // Arrange
            var userId   = Guid.NewGuid();
            var account1 = new BuyerAccount {
                CompanyName = "Brandscreen"
            };
            var account2 = new BuyerAccount {
                CompanyName = "WJsHome"
            };
            var accounts = new List <BuyerAccount> {
                account1, account2
            };

            var model = new AccountQueryViewModel {
                UserId = userId
            };

            Mock.Mock <IAccountService>().Setup(x => x.GetAccounts(It.IsAny <AccountQueryOptions>()))
            .Returns(accounts.ToAsyncEnumerable());
            Mock.Mock <IUserService>().Setup(x => x.GetUser(userId)).Returns(Task.FromResult(new User()));

            // Act
            var retVal = await Controller.Get(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkNegotiatedContentResult <PagedListViewModel <AccountListViewModel> > >());
            var content = ((OkNegotiatedContentResult <PagedListViewModel <AccountListViewModel> >)retVal).Content;

            Assert.That(content.TotalItemCount, Is.EqualTo(2));
            var data = content.Data.ToList();

            Assert.That(data[0].CompanyName, Is.EqualTo(account1.CompanyName));
            Assert.That(data[1].CompanyName, Is.EqualTo(account2.CompanyName));
        }
 public async Task UpdateAccount(BuyerAccount buyerAccount)
 {
     buyerAccount.UtcModifiedDateTime = _clock.UtcNow;
     _buyerAccountRepositoryAsync.Update(buyerAccount);
     await _brandscreenContext.SaveChangesAsync();
 }
 public BuyerAccount Add(BuyerAccount ba)
 {
     _unitOfWork.Repository <BuyerAccount>().Insert(ba);
     return(ba);
 }
 public void Update(BuyerAccount ba)
 {
     ba.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <BuyerAccount>().Update(ba);
 }
 public void Delete(BuyerAccount ba)
 {
     _unitOfWork.Repository <BuyerAccount>().Delete(ba);
 }
 public BuyerAccount Create(BuyerAccount ba)
 {
     ba.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <BuyerAccount>().Insert(ba);
     return(ba);
 }
        public void GetAdvertisers_ShouldReturnMatchedAdvertiser_WhenWithUserIdsOption()
        {
            // Arrange
            var userId       = Guid.NewGuid();
            var queryOptions = new AdvertiserQueryOptions();

            queryOptions.UserIds.Add(userId);

            var buyerAccount1 = new BuyerAccount {
                BuyerAccountId = 1
            };
            var buyerAccount2 = new BuyerAccount {
                BuyerAccountId = 2
            };
            var advertisers = new List <Advertiser>
            {
                new Advertiser
                {
                    BuyerAccountId      = buyerAccount1.BuyerAccountId,
                    BuyerAccount        = buyerAccount1,
                    UserAdvertiserRoles = new List <UserAdvertiserRole>
                    {
                        new UserAdvertiserRole {
                            UserId = userId
                        }
                    }
                },
                new Advertiser
                {
                    BuyerAccountId      = buyerAccount1.BuyerAccountId,
                    BuyerAccount        = buyerAccount1,
                    UserAdvertiserRoles = new List <UserAdvertiserRole>
                    {
                        new UserAdvertiserRole {
                            UserId = userId
                        }
                    }
                },
                new Advertiser
                {
                    BuyerAccountId      = buyerAccount2.BuyerAccountId,
                    BuyerAccount        = buyerAccount2,
                    UserAdvertiserRoles = new List <UserAdvertiserRole>
                    {
                        new UserAdvertiserRole {
                            UserId = userId
                        }
                    }
                },
            };

            MockUnitOfWorkRepository <Advertiser>().Setup(x => x.Queryable())
            .Returns(advertisers.ToAsyncEnumerable());

            // Act
            var retVal = Mock.Create <AdvertiserService>().GetAdvertisers(queryOptions).ToList();

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal.Count, Is.EqualTo(3));
        }