Exemple #1
0
        public void Constructor_GivenZeroOrNegativeExpiryInSeconds_ShouldThrowArgumentException()
        {
            //---------------Set up test pack-------------------
            var expiryInSeconds = RandomValueGenerator.CreateRandomInt(-100, 0);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var argumentException = Assert.Throws <ArgumentException>(() => new ThuriaCache <string>(expiryInSeconds));

            //---------------Test Result -----------------------
            argumentException.ParamName.Should().Be("expiryInSeconds");
        }
Exemple #2
0
        public void CreateRandomInt_GivenMinimumAndMaximumValues_ShouldGenerateValueBetweenGivenValues(int minimumValue, int maximumValue)
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var randomNumber = RandomValueGenerator.CreateRandomInt(minimumValue, maximumValue);

            //---------------Test Result -----------------------
            randomNumber.Should().BeGreaterOrEqualTo(minimumValue);
            randomNumber.Should().BeLessOrEqualTo(maximumValue);
        }
Exemple #3
0
        public void Constructor_GivenValue_ShouldSetSetPropertyValue()
        {
            //---------------Set up test pack-------------------
            var expiryInSeconds = RandomValueGenerator.CreateRandomInt(1, 10000);
            var thuriaCache     = new ThuriaCache <string>(expiryInSeconds);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var objectExpiry = thuriaCache.ExpiryInSeconds;

            //---------------Test Result -----------------------
            objectExpiry.Should().Be(expiryInSeconds);
        }
        public void WithCommandTimeout_GivenProvider_ShouldBuildContextWithProvider()
        {
            //---------------Set up test pack-------------------
            var commandTimeout = RandomValueGenerator.CreateRandomInt(100, 1000);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var databaseContext = SqlDatabaseContextBuilder.Create
                                  .WithConnectionStringProvider(Substitute.For <IConnectionStringProvider>())
                                  .WithDatabaseConnectionProvider(Substitute.For <IDatabaseConnectionProvider>())
                                  .WithStatementBuildProvider(Substitute.For <IStatementBuildProvider>())
                                  .WithDataModelPopulateProvider(Substitute.For <IDataModelPopulateProvider>())
                                  .WithCommandTimeout(commandTimeout)
                                  .Build();

            //---------------Test Result -----------------------
            databaseContext.Should().NotBeNull();
            databaseContext.CommandTimeout.Should().Be(commandTimeout);
        }
        public void CreateSubstituteDataReader_GivenData_And_AdditionalColumnValues_ShouldReturnDataReaderWithExpectedData()
        {
            //---------------Set up test pack-------------------
            var dataReaderData = new List <dynamic>
            {
                new { Id = Guid.NewGuid(), Name = RandomValueGenerator.CreateRandomString(10, 50) },
                new { Id = Guid.NewGuid(), Name = RandomValueGenerator.CreateRandomString(10, 50) },
                new { Id = Guid.NewGuid(), Name = RandomValueGenerator.CreateRandomString(10, 50) }
            };
            var additionalColumnValues = new Dictionary <string, object>
            {
                { "Sequence", RandomValueGenerator.CreateRandomInt(100, 500) },
                { "Amount", RandomValueGenerator.CreateRandomDecimal(1000, 5000) },
            };
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var dataReader = TestHelper.CreateSubstituteDataReader(dataReaderData, additionalColumnValues);
            //---------------Test Result -----------------------
            var allFakeData = new List <FakeDataClass>();

            while (dataReader.Read())
            {
                var dataClass = new FakeDataClass
                {
                    Id       = dataReader.GetValue <Guid>(nameof(FakeDataClass.Id)),
                    Name     = dataReader.GetValue <string>(nameof(FakeDataClass.Name)),
                    Sequence = dataReader.GetValue <int>(nameof(FakeDataClass.Sequence)),
                    Amount   = dataReader.GetValue <decimal>(nameof(FakeDataClass.Amount)),
                };
                allFakeData.Add(dataClass);
            }

            allFakeData.Count.Should().Be(3);

            foreach (var currentData in dataReaderData)
            {
                var foundDataClass = allFakeData.FirstOrDefault(dataClass => dataClass.Id.Equals(currentData.Id));
                foundDataClass.Should().NotBeNull();
                foundDataClass?.Name.Should().Be(currentData.Name);
                foundDataClass?.Sequence.Should().Be((int)additionalColumnValues["Sequence"]);
                foundDataClass?.Amount.Should().Be((decimal)additionalColumnValues["Amount"]);
            }
        }