Example #1
0
        public void SeedExtensions_AddSecondaryObjects_DbSet_HasItems()
        {
            // This test verifies that no items were seeded into the DB set when the DB set initially has items
            var modelDbSetPrimary   = new TestDbSet <PrimaryObject>();
            var modelDbSetSecondary = new TestDbSet <SecondaryObject>();
            var source = new List <SecondaryObject>()
            {
                new SecondaryObject(Guid.NewGuid()),
            };

            modelDbSetPrimary.AddRange(new[]
            {
                new PrimaryObject(Guid.NewGuid()),
                new PrimaryObject(Guid.NewGuid()),
                new PrimaryObject(Guid.NewGuid()),
                new PrimaryObject(Guid.NewGuid()),
            });
            modelDbSetSecondary.AddRange(source);
            _context.Setup(_ => _.Set <PrimaryObject>()).Returns(modelDbSetPrimary);
            _context.Setup(_ => _.Set <SecondaryObject>()).Returns(modelDbSetSecondary);
            _context.Object.AddSecondaryObjects();

            var destination = modelDbSetSecondary.ToList();

            Assert.IsNotNull(destination);
            Assert.AreEqual(source.Count, destination.Count);
        }
        public void GetAllParameters()
        {
            // Arrange
            int ElementsCountBeforeAct = parametersDbSet.Count();

            // Act
            IEnumerable <Parameter> allParameters = repository.GetAll();

            // Assert
            Assert.AreEqual(ElementsCountBeforeAct, allParameters.Count());
            Assert.AreEqual(
                parametersDbSet.First().ParameterName,
                allParameters.ToList()[0].ParameterName
                );
            Assert.AreEqual(
                parametersDbSet.ToList()[1].ParameterName,
                allParameters.ToList()[1].ParameterName
                );
        }
Example #3
0
        public void SeedExtensions_AddPrimaryObjects_DbSet_Empty()
        {
            // This test verifies that items were seeded into the DB set when the DB set is initially empty
            var modelDbSet = new TestDbSet <PrimaryObject>();
            var source     = new List <PrimaryObject>();

            modelDbSet.AddRange(source);
            _context.Setup(_ => _.Set <PrimaryObject>()).Returns(modelDbSet);
            _context.Object.AddPrimaryObjects();

            var destination = modelDbSet.ToList();

            Assert.IsNotNull(destination);
            Assert.AreNotEqual(source.Count, destination.Count);
        }
Example #4
0
        public void GetQueriesFromListByName_Test()
        {
            // Arrange
            string          select     = "select";
            string          person     = "person";
            List <SqlQuery> allQueries = queriesDbSet.ToList();

            int QueriesWithWordSelectAmount = 0;
            int QueriesWithWordPersonAmount = 0;

            foreach (SqlQuery query in queriesDbSet)
            {
                if (query.SqlQueryName.Contains(select))
                {
                    QueriesWithWordSelectAmount++;
                }
                if (query.SqlQueryName.Contains(person))
                {
                    QueriesWithWordPersonAmount++;
                }
            }

            // Act
            IEnumerable <SqlQuery> queryNameContainsSelect = queryRepo
                                                             .GetQueriesFromListByName(allQueries, select);
            IEnumerable <SqlQuery> queryNameContainsPerson = queryRepo
                                                             .GetQueriesFromListByName(allQueries, person);

            // Assert
            Assert.AreEqual(
                QueriesWithWordSelectAmount,
                queryNameContainsSelect.Count()
                );
            Assert.AreEqual(
                QueriesWithWordPersonAmount,
                queryNameContainsPerson.Count()
                );

            foreach (SqlQuery query in queryNameContainsSelect)
            {
                Assert.IsTrue(query.SqlQueryName.Contains(select));
            }
            foreach (SqlQuery query in queryNameContainsPerson)
            {
                Assert.IsTrue(query.SqlQueryName.Contains(person));
            }
        }
Example #5
0
        public void CreateQueryWithTwoParams_WhenSecondParameterIsNotNull()
        {
            // Arrange
            int queryElementsCountBeforeAct           = queriesDbSet.Count();
            int queryParametersElementsCountBeforeAct = queryParametersDbSet.Count();
            int parametersElementsCountBeforeAct      = parametersDbSet.Count();

            string createQueryName    = "New query";
            string createQueryContent = "string type";

            int    firstQueryParameterId     = parametersElementsCountBeforeAct + 1;
            string firstQueryParameterName   = "CreatedQueryFirstParameterName";
            string firstQueryParameterRuName = "первый параметр запроса";
            string firstQueryParameterType   = "text";

            int    secondQueryParameterId     = firstQueryParameterId + 1;
            string secondQueryParameterName   = "CreateQuerySecondParameterName";
            string secondQueryParameterRuName = "второй параметр запроса";
            string secondQueryParameterType   = "phone";

            SqlQuery queryToCreate = new SqlQuery()
            {
                SqlQueryId          = queryElementsCountBeforeAct + 1,
                SqlQueryName        = createQueryName,
                SqlQueryContent     = createQueryContent,
                SqlQueryCreatedDate = DateTime.Now
            };

            Parameter firstParameter = new Parameter()
            {
                ParameterId     = firstQueryParameterId,
                ParameterName   = firstQueryParameterName,
                ParameterRuName = firstQueryParameterRuName,
                ParameterType   = firstQueryParameterType
            };

            parametersDbSet.Add(firstParameter);
            Parameter secondParameter = new Parameter()
            {
                ParameterId     = secondQueryParameterId,
                ParameterName   = secondQueryParameterName,
                ParameterRuName = secondQueryParameterRuName,
                ParameterType   = secondQueryParameterType
            };

            parametersDbSet.Add(secondParameter);

            string[] parameterIds = new string[]
            {
                firstParameter.ParameterId.ToString(),
                     secondParameter.ParameterId.ToString()
            };

            // Act
            queryRepo.Create(queryToCreate, parameterIds);
            SqlQuery createdQuery         = queriesDbSet.Last();
            int      lastQueryParameterId = queryParametersDbSet.Last().SqlQueryParameterId;

            SqlQueryParameter[] twoLastQueryParameters = new SqlQueryParameter[]
            {
                queryParametersDbSet.Last(),
                                queryParametersDbSet.ToList()[queryParametersDbSet.Count() - 2]
            };

            // Assert
            Assert.IsTrue(queriesDbSet.Count() > queryElementsCountBeforeAct);
            Assert.IsTrue(parametersDbSet.Count() > parametersElementsCountBeforeAct);
            Assert.IsTrue(queryParametersDbSet.Count() > queryParametersElementsCountBeforeAct);

            foreach (SqlQueryParameter queryParameter in twoLastQueryParameters)
            {
                Assert.IsTrue(queryParameter.SqlQueryId == createdQuery.SqlQueryId);
                Assert.IsTrue(
                    queryParameter.ParameterId == firstQueryParameterId ||
                    queryParameter.ParameterId == secondQueryParameterId
                    );
            }
        }