Beispiel #1
0
        public void EditQueryWithTwoParams_WhenSecondParameterIsNull_ShouldRemoveParams()
        {
            // Arrange
            int queryElementsCountBeforeAct           = queriesDbSet.Count();
            int parametersElementsCountBeforeAct      = parametersDbSet.Count();
            int queryParametersElementsCountBeforeAct = queryParametersDbSet.Count();

            int      queryIdBeforeAct          = queriesDbSet.First().SqlQueryId;
            string   queryNameBeforeAct        = queriesDbSet.First().SqlQueryName;
            string   queryContentBeforeAct     = queriesDbSet.First().SqlQueryContent;
            DateTime queryCreatedDateBeforeAct = queriesDbSet.First().SqlQueryCreatedDate;

            string newQueryName    = "new query name";
            string newQueryContent = "new query content";

            int queryParametersCount = queryParametersDbSet
                                       .Where(p => p.SqlQueryId == queriesDbSet.First().SqlQueryId)
                                       .Count();

            SqlQuery queryToUpdate = queriesDbSet.First();

            queryToUpdate.SqlQueryName    = newQueryName;
            queryToUpdate.SqlQueryContent = newQueryContent;

            string[] parameterIds = null;

            // Act
            queryRepo.Edit(queryToUpdate, parameterIds);
            SqlQuery updatedQuery = queriesDbSet.ElementAt(queryToUpdate.SqlQueryId);

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

            Assert.AreEqual(newQueryName, updatedQuery.SqlQueryName);
            Assert.AreEqual(newQueryContent, updatedQuery.SqlQueryContent);
            Assert.AreEqual(queryCreatedDateBeforeAct, updatedQuery.SqlQueryCreatedDate);

            Assert.AreEqual(
                queryParametersElementsCountBeforeAct,
                (queryParametersDbSet.Count() + queryParametersCount)
                );

            Assert.IsTrue(
                queryParametersDbSet
                .Where(p => p.SqlQueryId == queryToUpdate.SqlQueryId)
                .Count() <= 0
                );
        }
        public void GetParameterById()
        {
            // Arrange
            int ElementsCountBeforeAct = parametersDbSet.Count();

            // Act
            Parameter parameter_1 = repository.Get(0);
            Parameter parameter_2 = repository.Get(1);

            // Assert
            Assert.AreEqual(
                parametersDbSet.ElementAt(0).ParameterName,
                parameter_1.ParameterName
                );
            Assert.AreEqual(parameter_1, parametersDbSet.ElementAt(0));

            Assert.AreEqual(
                parametersDbSet.ElementAt(1).ParameterName,
                parameter_2.ParameterName
                );
            Assert.AreEqual(parameter_2, parametersDbSet.ToList()[1]);

            Assert.AreEqual(ElementsCountBeforeAct, parametersDbSet.Count());
        }