Beispiel #1
0
        /// <summary>
        /// Functionality which can handle a query for getting some data for a household member.
        /// </summary>
        /// <param name="query">Query for getting some data for a household member.</param>
        /// <returns>View of the selected data.</returns>
        public virtual TView Query(TQuery query)
        {
            ArgumentNullGuard.NotNull(query, nameof(query));

            ITranslationInfo translationInfo = GetTranslationInfo(query);

            IHouseholdMember householdMember = HouseholdDataRepository.HouseholdMemberGetByMailAddress(ClaimValueProvider.MailAddress);

            if (householdMember == null)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberNotCreated));
            }
            if (ShouldBeActivated && householdMember.IsActivated == false)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberNotActivated));
            }
            if (ShouldHaveAcceptedPrivacyPolicy && householdMember.IsPrivacyPolicyAccepted == false)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberHasNotAcceptedPrivacyPolicy));
            }
            if (householdMember.HasRequiredMembership(RequiredMembership) == false)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberHasNotRequiredMembership));
            }

            TData data = GetData(householdMember, query, translationInfo);

            return(ObjectMapper.Map <TData, TView>(data, translationInfo?.CultureInfo));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the household identifier from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader from which to read.</param>
        /// <param name="columnName">The column name for value to read.</param>
        /// <returns>The household identifier.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or <paramref name="columnName"/> is null, empty or white space.</exception>
        private static Guid GetHouseholdIdentifier(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(new Guid(dataReader.GetString(columnName)));
        }
Beispiel #3
0
        /// <summary>
        /// Gets the time for when the household was created from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader from which to read.</param>
        /// <param name="columnName">The column name for value to read.</param>
        /// <returns>The time for when the household was created.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or <paramref name="columnName"/> is null, empty or white space.</exception>
        private static DateTime GetCreationTime(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(dataReader.GetMySqlDateTime(columnName).Value.ToLocalTime());
        }
        /// <summary>
        /// Danner en data provider, som benytter MySql.
        /// </summary>
        /// <param name="mySqlConnection">Eksisterende MySql connection.</param>
        /// <param name="clonedWithReusableConnection">True, ved en genbrugelig conntion ellers false.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="mySqlConnection"/> is null.</exception>
        protected MySqlDataProvider(MySqlConnection mySqlConnection, bool clonedWithReusableConnection)
        {
            ArgumentNullGuard.NotNull(mySqlConnection, nameof(mySqlConnection));

            _mySqlConnection = mySqlConnection;
            _clonedWithReusableConnection = clonedWithReusableConnection;
        }
Beispiel #5
0
        /// <summary>
        /// Gets the temperature from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader from which to read.</param>
        /// <param name="columnName">The column name for value to read.</param>
        /// <returns>The temperature.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or <paramref name="columnName"/> is null, empty or white space.</exception>
        private static int GetTemperature(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(dataReader.GetInt16(columnName));
        }
        /// <summary>
        /// Adds a payment reference parameter to the command.
        /// </summary>
        /// <param name="value">The value for the payment reference.</param>
        /// <returns>This instance of the <see cref="HouseholdDataCommandBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal HouseholdDataCommandBuilder AddPaymentReferenceParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@paymentReference", value, 128);
            return(this);
        }
        /// <summary>
        /// Henter og returnerer data fra MySql.
        /// </summary>
        /// <typeparam name="TDataProxy">Typen på data proxy med data fra MySql.</typeparam>
        /// <param name="queryCommand">Database command for the SQL query statement.</param>
        /// <returns>Collection indeholdende data proxies.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="queryCommand"/> is null.</exception>
        public override IEnumerable <TDataProxy> GetCollection <TDataProxy>(MySqlCommand queryCommand)
        {
            ArgumentNullGuard.NotNull(queryCommand, nameof(queryCommand));

            Open();
            try
            {
                List <TDataProxy> collection = new List <TDataProxy>();
                using (MySqlCommand command = queryCommand)
                {
                    command.Connection = _mySqlConnection;
                    using (MySqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.HasRows == false)
                        {
                            reader.Close();
                            return(collection);
                        }
                        while (reader.Read())
                        {
                            TDataProxy dataProxy = new TDataProxy();
                            dataProxy.MapData(reader, this);
                            collection.Add(dataProxy);
                        }
                        reader.Close();
                    }
                }
                collection.ForEach(proxy => proxy.MapRelations(this));
                return(collection);
            }
            finally
            {
                Close();
            }
        }
        /// <summary>
        /// Adds a translation value parameter to the command.
        /// </summary>
        /// <param name="value">The value for the translation value.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal SystemDataCommandBuilder AddTranslationValueParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@value", value, 4096);
            return(this);
        }
Beispiel #9
0
        /// <summary>
        /// Maps data from the data reader.
        /// </summary>
        /// <param name="dataReader">Data reader.</param>
        /// <param name="dataProvider">Implementation of the data provider used to access data.</param>
        public virtual void MapData(MySqlDataReader dataReader, IDataProviderBase <MySqlDataReader, MySqlCommand> dataProvider)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNull(dataProvider, nameof(dataProvider));

            Identifier              = new Guid(dataReader.GetString("ForeignKeyIdentifier"));
            DataProvider            = dataProvider.Create(new DataProviderProxy(), dataReader, "DataProviderIdentifier", "DataProviderName", "HandlesPayments", "DataSourceStatementIdentifier");
            ForeignKeyForIdentifier = new Guid(dataReader.GetString("ForeignKeyForIdentifier"));
            ForeignKeyValue         = dataReader.GetString("ForeignKeyValue");

            IList <Type> foreignKeyForTypes = new List <Type>();

            foreach (var foreignKeyForTypeName in dataReader.GetString("ForeignKeyForTypes").Split(';').Where(m => string.IsNullOrWhiteSpace(m) == false))
            {
                // ReSharper disable EmptyGeneralCatchClause
                try
                {
                    var typeName = foreignKeyForTypeName;
                    var assembly = typeof(IDomainObject).Assembly;
                    var type     = assembly.GetTypes().SingleOrDefault(m => string.Compare(m.Name, typeName, StringComparison.Ordinal) == 0);
                    if (type != null)
                    {
                        foreignKeyForTypes.Add(type);
                    }
                }
                catch
                {
                    // Don't throw the exception. Just ignore the type.
                }
                // ReSharper restore EmptyGeneralCatchClause
            }
            ForeignKeyForTypes = foreignKeyForTypes;

//            DataProviderIdentifier = new Guid(dataReader.GetString("DataProviderIdentifier"));
        }
        /// <summary>
        /// Adds a foreign key value parameter to the command.
        /// </summary>
        /// <param name="value">The value for the foreign key value.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal SystemDataCommandBuilder AddForeignKeyValueParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@foreignKeyValue", value, 128);
            return(this);
        }
        /// <summary>
        /// Adds a data provider name parameter to the command.
        /// </summary>
        /// <param name="value">The value for the data provider name.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal SystemDataCommandBuilder AddDataProviderNameParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@name", value, 256);
            return(this);
        }
        /// <summary>
        /// Adds a foreign key for types like parameter to the command.
        /// </summary>
        /// <param name="value">The value for the foreign key for types.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null.</exception>
        internal SystemDataCommandBuilder AddForeignKeyForTypesLikeParameter(Type value)
        {
            ArgumentNullGuard.NotNull(value, nameof(value));

            AddVarCharParameter("@foreignKeyForTypes", $"%{value.Name}%", 128);
            return(this);
        }
        /// <summary>
        /// Adds a foreign key for types parameter to the command.
        /// </summary>
        /// <param name="value">The value for the foreign key for types.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null.</exception>
        internal SystemDataCommandBuilder AddForeignKeyForTypesParameter(IEnumerable <Type> value)
        {
            ArgumentNullGuard.NotNull(value, nameof(value));

            AddVarCharParameter("@foreignKeyForTypes", string.Join(";", value.Select(m => m.Name)), 128);
            return(this);
        }
        /// <summary>
        /// Gets the membership from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader from which to read.</param>
        /// <param name="columnName">The column name for value to read.</param>
        /// <returns>The membership.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or <paramref name="columnName"/> is null, empty or white space.</exception>
        private static Membership GetMembership(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return((Membership)dataReader.GetInt16(columnName));
        }
        /// <summary>
        /// Gets the appointment note from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <param name="columnName">Column name.</param>
        /// <returns>Appointment note.</returns>
        private static string GetAppointmentNote(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(dataReader.IsDBNull(dataReader.GetOrdinal(columnName)) ? null : dataReader.GetString(columnName));
        }
Beispiel #16
0
        /// <summary>
        /// Deletes the bindings which bind a given household to all the household members who has membership.
        /// </summary>
        /// <param name="dataProvider">Implementation of the data provider used to access data.</param>
        /// <param name="householdProxy">Data proxy for the household on which to delete the bindings.</param>
        /// <returns>Affected household members.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataProvider"/> or <paramref name="householdProxy"/> is null.</exception>
        internal static IEnumerable <IHouseholdMemberProxy> DeleteMemberOfHouseholds(IDataProviderBase <MySqlDataReader, MySqlCommand> dataProvider, IHouseholdProxy householdProxy)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider))
            .NotNull(householdProxy, nameof(householdProxy));

            return(DeleteMemberOfHouseholds(dataProvider, () => GetMemberOfHouseholds(dataProvider, householdProxy).ToArray(), memberOfHouseholdProxy => memberOfHouseholdProxy.HouseholdMember as IHouseholdMemberProxy));
        }
        /// <summary>
        /// Adds a mail address parameter to the command.
        /// </summary>
        /// <param name="value">The value for the mail address.</param>
        /// <returns>This instance of the <see cref="HouseholdDataCommandBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal HouseholdDataCommandBuilder AddMailAddressParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@mailAddress", value, 128);
            return(this);
        }
Beispiel #18
0
        /// <summary>
        /// Gets a food group by a given data providers foreign key.
        /// </summary>
        /// <param name="dataProvider">Data provider.</param>
        /// <param name="foreignKeyValue">Foreign key value.</param>
        /// <returns>Food group.</returns>
        public virtual IFoodGroup FoodGroupGetByForeignKey(IDataProvider dataProvider, string foreignKeyValue)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider))
            .NotNullOrWhiteSpace(foreignKeyValue, nameof(foreignKeyValue));

            try
            {
                if (dataProvider.Identifier.HasValue == false)
                {
                    throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, dataProvider.Identifier, "Identifier"));
                }

                MySqlCommand command = FoodGroupProxy.BuildSystemDataCommandForSelecting(
                    "INNER JOIN ForeignKeys AS fk ON fk.ForeignKeyForIdentifier=fg.FoodGroupIdentifier WHERE fk.DataProviderIdentifier=@dataProviderIdentifier AND fk.ForeignKeyForTypes LIKE @foreignKeyForTypes AND fk.ForeignKeyValue=@foreignKeyValue",
                    systemCommandBuilder => systemCommandBuilder
                    .AddDataProviderIdentifierParameter(dataProvider.Identifier)
                    .AddForeignKeyForTypesLikeParameter(typeof(IFoodGroup))
                    .AddForeignKeyValueParameter(foreignKeyValue));
                return(DataProvider.GetCollection <FoodGroupProxy>(command).FirstOrDefault());
            }
            catch (IntranetRepositoryException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, MethodBase.GetCurrentMethod().Name, ex.Message), ex);
            }
        }
        /// <summary>
        /// Adds a household name parameter to the command.
        /// </summary>
        /// <param name="value">The value for the household name.</param>
        /// <returns>This instance of the <see cref="HouseholdDataCommandBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null, empty or white space.</exception>
        internal HouseholdDataCommandBuilder AddHouseholdNameParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@name", value, 64);
            return(this);
        }
        /// <summary>
        /// Build a mockup for a foreign key to a domain object in the food waste domain.
        /// </summary>
        /// <param name="foreignKeyForIdentifier">Identifier for the domain object which has the foreign key.</param>
        /// <param name="foreignKeyForType">Type on which has the foreign key.</param>
        /// <param name="dataProvider">Data provider who owns the foreign key.</param>
        /// <returns>Mockup for a foreign key to a to a domain object in the food waste domain.</returns>
        public static IForeignKey BuildForeignKeyMock(Guid foreignKeyForIdentifier, Type foreignKeyForType, IDataProvider dataProvider = null)
        {
            ArgumentNullGuard.NotNull(foreignKeyForType, nameof(foreignKeyForType));

            IForeignKey foreignKeyMock = MockRepository.GenerateMock <IForeignKey>();

            foreignKeyMock.Stub(m => m.Identifier)
            .Return(Guid.NewGuid())
            .Repeat.Any();
            foreignKeyMock.Stub(m => m.DataProvider)
            .Return(dataProvider ?? BuildDataProviderMock())
            .Repeat.Any();
            foreignKeyMock.Stub(m => m.ForeignKeyForIdentifier)
            .Return(foreignKeyForIdentifier)
            .Repeat.Any();
            foreignKeyMock.Stub(m => m.ForeignKeyForTypes)
            .Return(new List <Type> {
                typeof(IDomainObject), typeof(IIdentifiable), foreignKeyForType
            })
            .Repeat.Any();
            foreignKeyMock.Stub(m => m.ForeignKeyValue)
            .Return(Fixture.Create <string>())
            .Repeat.Any();
            return(foreignKeyMock);
        }
        /// <summary>
        /// Danner en data provider, som benytter MySql.
        /// </summary>
        /// <param name="connectionStringSettings">Konfiguration for en connection streng.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="connectionStringSettings"/> is null.</exception>
        public MySqlDataProvider(ConnectionStringSettings connectionStringSettings)
        {
            ArgumentNullGuard.NotNull(connectionStringSettings, nameof(connectionStringSettings));

            _mySqlConnection = new MySqlConnection(connectionStringSettings.ConnectionString);
            _clonedWithReusableConnection = false;
        }
        /// <summary>
        /// Adds the parameter for the title.
        /// </summary>
        /// <param name="value">The value for the title.</param>
        /// <returns>Command builder which can build command to the common repository.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="value"/> is null, empty or white space.</exception>
        internal CommonCommandBuilder AddTitleParameter(string value)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(value, nameof(value));

            AddVarCharParameter("@title", value, 50);
            return(this);
        }
        /// <summary>
        /// Gets whether the storage type is deletable from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader from which to read.</param>
        /// <param name="columnName">The column name for value to read.</param>
        /// <returns>Whether the storage type is deletable or not.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or <paramref name="columnName"/> is null, empty or white space.</exception>
        private static bool GetDeletable(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(Convert.ToBoolean(dataReader.GetInt32(columnName)));
        }
        /// <summary>
        /// Gets the appointment identifier from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <param name="columnName">Column name.</param>
        /// <returns>Appointment identifier.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or when <paramref name="columnName"/> is null, empty or whitespace.</exception>
        private static int GetAppointmentIdentifier(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(dataReader.GetInt32(columnName));
        }
        /// <summary>
        /// Creates a command handler which handles a command for removing a household member from a given household on the current users household account.
        /// </summary>
        /// <param name="householdDataRepository">Implementation of a repository which can access household data for the food waste domain.</param>
        /// <param name="claimValueProvider">Implementation of a provider which can resolve values from the current users claims.</param>
        /// <param name="foodWasteObjectMapper">Implementation of an object mapper which can map objects in the food waste domain.</param>
        /// <param name="specification">Implementation of a specification which encapsulates validation rules.</param>
        /// <param name="commonValidations">Implementation of common validations.</param>
        /// <param name="domainObjectValidations">Implementation of common validations used by domain objects in the food waste domain.</param>
        /// <param name="exceptionBuilder">Implementation of a builder which can build exceptions.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="domainObjectValidations"/> is null.</exception>
        public HouseholdRemoveHouseholdMemberCommandHandler(IHouseholdDataRepository householdDataRepository, IClaimValueProvider claimValueProvider, IFoodWasteObjectMapper foodWasteObjectMapper, ISpecification specification, ICommonValidations commonValidations, IDomainObjectValidations domainObjectValidations, IExceptionBuilder exceptionBuilder)
            : base(householdDataRepository, claimValueProvider, foodWasteObjectMapper, specification, commonValidations, exceptionBuilder)
        {
            ArgumentNullGuard.NotNull(domainObjectValidations, nameof(domainObjectValidations));

            _domainObjectValidations = domainObjectValidations;
        }
        /// <summary>
        /// Gets an appointment time from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <param name="columnName">Column name.</param>
        /// <returns>Appointment time.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or when <paramref name="columnName"/> is null, empty or whitespace.</exception>
        private static TimeSpan GetAppointmentTime(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(dataReader.GetTimeSpan(columnName));
        }
Beispiel #27
0
        /// <summary>
        /// Gets the name from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader from which to read.</param>
        /// <param name="columnName">The column name for value to read.</param>
        /// <returns>The name.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataReader"/> is null or <paramref name="columnName"/> is null, empty or white space.</exception>
        private static string GetName(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(dataReader.GetString(columnName));
        }
        /// <summary>
        /// Gets the appointment properties from the data reader.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <param name="columnName">Column name.</param>
        /// <returns>Appointment properties.</returns>
        private static int GetAppointmentProperties(MySqlDataReader dataReader, string columnName)
        {
            ArgumentNullGuard.NotNull(dataReader, nameof(dataReader))
            .NotNullOrWhiteSpace(columnName, nameof(columnName));

            return(dataReader.IsDBNull(dataReader.GetOrdinal(columnName)) ? 0 : dataReader.GetInt32(columnName));
        }
        /// <summary>
        /// Creates a builder which can build a database command tester.
        /// </summary>
        /// <param name="commandText">The expected command text.</param>
        /// <param name="commandType">The expected command type.</param>
        /// <param name="commandTimeout">The expected command timeout.</param>
        public DbCommandTestBuilder(string commandText, CommandType commandType = CommandType.Text, int commandTimeout = 30)
        {
            ArgumentNullGuard.NotNullOrWhiteSpace(commandText, nameof(commandText));

            IDataParameterCollection dataParameterCollection = MockRepository.GenerateMock <IDataParameterCollection>();

            dataParameterCollection.Stub(m => m.Count)
            .WhenCalled(e => e.ReturnValue = _dataParameterCollection.Count)
            .Return(0)
            .Repeat.Any();
            dataParameterCollection.Stub(m => m[Arg <string> .Is.Anything])
            .WhenCalled(e => e.ReturnValue = _dataParameterCollection.SingleOrDefault(m => string.CompareOrdinal((string)e.Arguments.ElementAt(0), m.ParameterName) == 0))
            .Return(null)
            .Repeat.Any();

            _expectedDbCommand = MockRepository.GenerateMock <IDbCommand>();
            _expectedDbCommand.Stub(m => m.CommandText)
            .Return(commandText)
            .Repeat.Any();
            _expectedDbCommand.Stub(m => m.CommandType)
            .Return(commandType)
            .Repeat.Any();
            _expectedDbCommand.Stub(m => m.CommandTimeout)
            .Return(commandTimeout)
            .Repeat.Any();
            _expectedDbCommand.Stub(m => m.Parameters)
            .WhenCalled(e => e.ReturnValue = dataParameterCollection)
            .Return(null)
            .Repeat.Any();
        }
Beispiel #30
0
        /// <summary>
        /// Tests the database command.
        /// </summary>
        /// <param name="expected">The expected database command.</param>
        /// <param name="actual">The actual database command.</param>
        /// <param name="resultBuilder">The result builder.</param>
        private static void CommandTester(IDbCommand expected, IDbCommand actual, StringBuilder resultBuilder)
        {
            ArgumentNullGuard.NotNull(expected, nameof(expected))
            .NotNull(actual, nameof(actual))
            .NotNull(resultBuilder, nameof(resultBuilder));

            if (string.CompareOrdinal(expected.CommandText, actual.CommandText) != 0)
            {
                resultBuilder.AppendLine("CommandText does not match:");
                resultBuilder.AppendLine($"- Expected:\t{expected.CommandText}");
                resultBuilder.AppendLine($"- But was:\t{actual.CommandText}");
            }

            if (expected.CommandType != actual.CommandType)
            {
                resultBuilder.AppendLine("CommandType does not match:");
                resultBuilder.AppendLine($"- Expected:\t{expected.CommandType}");
                resultBuilder.AppendLine($"- But was:\t{actual.CommandType}");
            }

            if (expected.CommandTimeout != actual.CommandTimeout)
            {
                resultBuilder.AppendLine("CommandTimeout does not match:");
                resultBuilder.AppendLine($"- Expected:\t{expected.CommandTimeout}");
                resultBuilder.AppendLine($"- But was:\t{actual.CommandTimeout}");
            }
        }