示例#1
0
        /// <summary>
        /// Updates UserName and LoweredUserName for an user.
        /// </summary>
        /// <param name="userExtension"></param>
        /// <param name="updatedByUserId"></param>
        /// <returns>Returns number of affected rows.</returns>
        public int Execute(UserExtension userExtension, Guid updatedByUserId)
        {
            // in parameters
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(Parameters.UserId, userExtension.UserId),
                DbHelper.CreateParameter(Parameters.UserStatusCode, userExtension.UserStatusCode),
                DbHelper.CreateParameter(Parameters.FirstName, userExtension.FirstName),
                DbHelper.CreateParameter(Parameters.LastName, userExtension.LastName),
                DbHelper.CreateParameter(Parameters.PrimaryBusinessId, userExtension.PrimaryBusinessId),
                DbHelper.CreateParameter(Parameters.CultureCode, userExtension.CultureCode),
                DbHelper.CreateParameter(Parameters.UpdatedByUserId, updatedByUserId),
            };

            return DbHelper.ExecuteNonQueryCommand(this, parameters);
        }
示例#2
0
        public void Execute(UserExtension userExtension, Guid createdByUserId)
        {
            // in parameters
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(Parameters.UserId, userExtension.UserId),
                DbHelper.CreateParameter(Parameters.PrimaryBusinessId, userExtension.PrimaryBusinessId),
                DbHelper.CreateParameter(Parameters.FirstName, userExtension.FirstName),
                DbHelper.CreateParameter(Parameters.LastName, userExtension.LastName),
                DbHelper.CreateParameter(Parameters.CultureCode, userExtension.CultureCode),
                DbHelper.CreateParameter(Parameters.UpdatedDatetime, DateTime.UtcNow),
                DbHelper.CreateParameter(Parameters.UpdatedByUserId, createdByUserId)
            };

            DbHelper.ExecuteNonQueryCommand(this, parameters);
        }
示例#3
0
            public void EagleBusinessToEcomBusinessReturnsBusinessAccountWithMappedProperties()
            {
                // Arrange
                var createdByUser = new UserExtension {FirstName = "John", LastName = "Doe"};
                var updatedByUser = new UserExtension {FirstName = "Dummy", LastName = "User"};

                var eagleBusiness = new Model.Business.Business
                {
                    Id = 12345,
                    Name = "Business 1", 
                    ShortName = "Bus1", 
                    MerchantDetails = new MerchantDetails(),
                    CreatedByUser = createdByUser, 
                    UpdatedByUser = updatedByUser,
                    ReferenceCode = "Bus000001",
                    Provider = new Provider { ContentId = "1544BCC" },
                    OnlineBookingScenarios = new Collection<OnlineBookingScenario>()
                };
                
                // Act
                List<string> missedChannels;
                EcomBusinessAccount ecommBusiness = EcomConverter.EagleBusinessToEcom(eagleBusiness, string.Empty, out missedChannels);

                // Assert
                Assert.AreEqual(string.Empty, ecommBusiness.CreatedByTitle, "CreatedByTitle should be empty");
                Assert.AreEqual(createdByUser.FirstName, ecommBusiness.CreatedByFirstname, "CreatedByFirstname doesn't match");
                Assert.AreEqual(createdByUser.LastName, ecommBusiness.CreatedByLastname, "CreatedByLastname doesn't match");
                Assert.AreEqual(string.Empty, ecommBusiness.ModifiedByTitle, "ModifiedByTitle should be empty");
                Assert.AreEqual(updatedByUser.FirstName, ecommBusiness.ModifiedByFirstname, "ModifiedByFirstname doesn't match");
                Assert.AreEqual(updatedByUser.LastName, ecommBusiness.ModifiedByLastname, "ModifiedByLastname doesn't match");
                Assert.AreEqual(EcomConverter.EXTERNAL_PRODUCT_PROVIDER_CODE, ecommBusiness.BusinessAccountTypeId, "BusinessAccountTypeId doesn't match");
                Assert.AreEqual(eagleBusiness.Name, ecommBusiness.FullName, "FullName doesn't match");
                Assert.AreEqual(eagleBusiness.ShortName, ecommBusiness.ShortName, "ShortName doesn't match");
                Assert.AreEqual(eagleBusiness.ReferenceCode, ecommBusiness.ReferenceCode, "ReferenceCode doesn't match");
                Assert.AreEqual(eagleBusiness.Provider.ContentId, ecommBusiness.ContentId, "ContentId doesn't match");
                Assert.IsFalse(ecommBusiness.IsMerchant, "IsMerchant should be false");
            }
示例#4
0
        /// <summary>
        /// Modify UserExtension
        /// </summary>
        /// <param name="userExtension">UserExtension</param>
        public bool Modify(UserExtension userExtension)
        {
            if (string.Equals(userExtension.CultureCode, DEFAULT_CULTURE_CODE, StringComparison.InvariantCultureIgnoreCase))
            {
                userExtension.CultureCode = null;
            }

            var updatedByUserId = AuditFieldsHelper.GetUserId();

            int rowsAffected = new StoredProcedures.Security.UpdateUserExtensionMapper().Execute(userExtension, updatedByUserId);

            // Check if the update was successful and return
            if (rowsAffected == 0)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30027, "UserExtensionDao.Modify",
                    additionalDescriptionParameters: (new object[] { typeof(UserExtension).Name, userExtension.UserId }),
                    arguments: new object[] { typeof(UserExtension).Name, userExtension.UserId }));
            }

            return true;
        }
示例#5
0
 /// <summary>
 /// Inserts a user / business pair into the extension table
 /// </summary>   
 /// <param name="userExtension">User extension</param>
 public void Create(UserExtension userExtension)
 {
     var createdByUserId = AuditFieldsHelper.GetUserId();
     new StoredProcedures.Security.InsertUserExtensionMapper().Execute(userExtension, createdByUserId);
 }
示例#6
0
            public void LinkToBusiness()
            {
                // Arrange
                const int BUSINESS_ID = 1;
                var userId = new Guid();

                var userBusinessDao = MockRepository.GenerateMock<IUserBusinessDao>();
                var userExtensionDao = MockRepository.GenerateMock<IUserExtensionDao>();
                var stubUserEventDao = MockRepository.GenerateStub<IUserEventDao>();

                userManager.UserBusinessDao = userBusinessDao;
                userManager.UserExtensionDao = userExtensionDao;
                userManager.UserEventDao = stubUserEventDao;

                var userExtension = new UserExtension { UserId = userId };

                userBusinessDao.Stub(u => u.AddBusinessToUser(Arg<Guid>.Is.Equal(userId), Arg<long>.Is.Equal(BUSINESS_ID))).Return(true);

                userExtensionDao.Stub(u => u.GetByKey(Arg<Guid>.Is.Equal(userId))).Return(userExtension);
                userExtensionDao.Stub(u => u.Modify(Arg<UserExtension>.Is.Equal(userExtension))).Return(true);

                stubUserEventDao.Expect(u => u.Create(Arg<UserEvent>.Is.Anything));

                // Act
                var result = userManager.AddBusinessToUser(userId, BUSINESS_ID);

                //Assert
                Assert.IsTrue(result, "User was not linked to business successfully.");
                stubUserEventDao.VerifyAllExpectations();
            }
示例#7
0
            public void RemoveNonPrimaryBusinessFromUser()
            {
                // Arrange
                const long BUSINESS_ID1 = 1;
                const long BUSINESS_ID2 = 2;
                var userId = new Guid();

                var userBusinessDao = MockRepository.GenerateMock<IUserBusinessDao>();
                var stubUserEventDao = MockRepository.GenerateStub<IUserEventDao>();
                var userExtensionDao = MockRepository.GenerateMock<IUserExtensionDao>();

                userManager.UserBusinessDao = userBusinessDao;
                userManager.UserEventDao = stubUserEventDao;
                userManager.UserExtensionDao = userExtensionDao;

                userBusinessDao.Stub(u => u.GetFirstBusiness(Arg<Guid>.Is.Equal(userId))).Return(BUSINESS_ID2);

                var userExtension = new UserExtension
                {
                    UserId = userId,
                    PrimaryBusinessId = BUSINESS_ID2
                };

                userExtensionDao.Stub(u => u.GetByKey(Arg<Guid>.Is.Equal(userId))).Return(userExtension);
                userExtensionDao.Stub(u => u.Modify(Arg<UserExtension>.Is.Equal(userExtension))).Return(true);

                // Act
                userManager.RemoveBusinessFromUser(userId, BUSINESS_ID1);

                //Assert
                userBusinessDao.AssertWasCalled(a => a.RemoveBusinessFromUser(userId, BUSINESS_ID1));
                userBusinessDao.AssertWasNotCalled(a => a.GetFirstBusiness(userId));
                userExtensionDao.AssertWasNotCalled(a => a.Modify(userExtension));
                stubUserEventDao.AssertWasCalled(u => u.Create(Arg<UserEvent>.Is.Anything));
            }
示例#8
0
            public void ModifyUserExtensionWithNonExistantUserIdExpectExpectedResultException()
            {
                // Arrange
                UserExtension userExtension = new UserExtension();
                userExtension.UserId = new Guid();
                userExtension.FirstName = userExtension.FirstName + "UPDATED";
                userExtension.LastName = userExtension.LastName + "UPDATED";
                userExtension.CultureCode = userExtension.CultureCode + "UPDATED";

                try
                {
                    //Act
                    userExtensionDao.Modify(userExtension);

                    Assert.Fail("An exception of type ExpectedResultException should have been thrown");
                }
                catch (ExpectedResultException ex)
                {
                    Assert.AreEqual(ex.Code, "SRVEX30027", "Exception code returned is incorrect.");
                }

            }
示例#9
0
        /// <summary>
        /// Activate a user based on the activation token, user extension and activation request
        /// </summary>
        /// <param name="userExtension">The user extension</param>
        /// <param name="activationRequest">The activation request</param>
        /// <returns>The activated user name</returns>
        private string ActivateUser(UserExtension userExtension, ActivationRequest activationRequest, string activationType)
        {
            MembershipUser user = membership.GetUser(userExtension.UserId);

            bool isUpdated = false;

            // NOTE: This condition seems to be wrong, because the return user.UserName statement at the end of this method could be called on a potentially null object.
            if (user != null)
            {
                using (BusinessTransaction tx = new BusinessTransaction())
                {
                    //unlock user if user is locked
                    if (userExtension.UserStatusCode == UserStatusEnum.Locked.GetCode())
                    {
                        user.UnlockUser();
                    }

                    userExtension.UserStatusCode = USER_STATUS_ACTIVATED;

                    bool isChangePassword = membership.ChangePassword(user, activationRequest.Password);

                    bool isChangeQuestionAndAnswer = membership.ChangeSecurityQuestionAndAnswer(
                                                                        user,
                                                                        activationRequest.Password,
                                                                        activationRequest.SecurityQuestionId.ToString(),
                                                                        activationRequest.Answer);

                    isUpdated = userExtensionDao.Modify(userExtension);

                    if (activationType == RESETPASSWORD_TYPE_CODE)
                    {
                        userManager.RecordUserEvent(userExtension.UserId, UserEventTypesEnum.UserReActivated);
                    }
                    else if (activationType == ACTIVATION_TYPE_CODE)
                    {
                        userManager.RecordUserEvent(userExtension.UserId, UserEventTypesEnum.UserActivated);
                    }

                    if (isUpdated == false || isChangePassword == false || isChangeQuestionAndAnswer == false)
                    {
                        tx.Rollback();
                    }

                    tx.Commit();
                }
            }

            return user.UserName;
        }
示例#10
0
            public void EagleBusinessToEcomBusinessMapsChannelNames()
            {
                // Arrange
                var channelNames = new List<string> { "Channel1", "Channel3", "Channel3", "Channel4", "Channel5" };

                var createdByUser = new UserExtension { FirstName = "John", LastName = "Doe" };
                var updatedByUser = new UserExtension { FirstName = "Dummy", LastName = "User" };

                const int BUSINESS_ID = 12345;
                const string SYNC_CODE_UK = "UK";
                const string SYNC_CODE_IN = "IN";
                const string CHANNEL_6_NAME = "Channel6";

                var businessChannelOptIn = new BusinessChannelOptIn
                                               {
                                                   BusinessId = BUSINESS_ID,
                                                   PrePaySettings = new BusinessChannelPrePaySettings
                                                                        {
                                                                            Type = PrePayRuleTypeEnum.Amount,
                                                                            Value = 1,
                                                                            BusinessId = BUSINESS_ID
                                                                        }
                                               };

                var eagleBusiness = new Model.Business.Business
                {
                    Id = BUSINESS_ID,
                    Name = "Business 1",
                    ShortName = "Bus1",
                    CreatedByUser = createdByUser,
                    UpdatedByUser = updatedByUser,
                    Distributors = new Collection<Distributor>
                    {
                        new Distributor 
                        { 
                            Channels = new List<Channel>
                            {
                                new Channel { ShortName = channelNames[0], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = channelNames[1], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = channelNames[2], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                            }
                        },
                        new Distributor 
                        { 
                            Channels = new List<Channel>
                            {
                                new Channel { ShortName = channelNames[3], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = channelNames[4], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = CHANNEL_6_NAME, BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_IN}
                            }
                        }
                    },
                    OnlineBookingScenarios = new Collection<OnlineBookingScenario>(),
                    MerchantDetails = new MerchantDetails(),
                    Provider = new Provider { ContentId = BUSINESS_ID.ToString(CultureInfo.InvariantCulture) }
                };

                // Act
                List<string> missedChannels;
                var ecommBusiness = EcomConverter.EagleBusinessToEcom(eagleBusiness, SYNC_CODE_UK, out missedChannels);

                foreach (var channelName in channelNames)
                {
                    Assert.True(ecommBusiness.Channels.Any(c => c.ChannelName == channelName), string.Format("{0} not found in ecommBusiness.Channels", channelName));
                }

                Assert.False(ecommBusiness.Channels.Any(c => c.ChannelName == CHANNEL_6_NAME), string.Format("{0} found in ecommBusiness.Channels", CHANNEL_6_NAME));

                Assert.IsTrue(missedChannels.Contains(CHANNEL_6_NAME), string.Format("{0} channel name was not missed", CHANNEL_6_NAME));
            }