public void Supplier_CreateNewSupplierInvalid_ContextCountZero()
        {
            supplierController.ModelState.AddModelError("Test", "Test");
            var result = supplierController.Create(GetMockSupplier());

            Assert.AreEqual(0, context.Count());
        }
示例#2
0
        public void CreateQueryWithTwoParams_WhenSecondParameterIsNull()
        {
            // Arrange
            int queryElementsCountBeforeAct           = queriesDbSet.Count();
            int queryParametersElementsCountBeforeAct = queryParametersDbSet.Count();

            string newQueryName    = "New query";
            string newQueryСontent = "string type";

            SqlQuery queryToCreate = new SqlQuery()
            {
                SqlQueryId          = queryElementsCountBeforeAct + 1,
                SqlQueryName        = newQueryName,
                SqlQueryContent     = newQueryСontent,
                SqlQueryCreatedDate = DateTime.Now
            };

            string[] parameterIds = null;

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

            // Assert
            Assert.AreNotEqual(queryElementsCountBeforeAct, queriesDbSet.Count());
            Assert.AreEqual(queryParametersElementsCountBeforeAct, queryParametersDbSet.Count());

            Assert.AreEqual(newQueryName, createdQuery.SqlQueryName);
            Assert.AreEqual(newQueryСontent, createdQuery.SqlQueryContent);
        }
示例#3
0
        public void Execute_GivenAddUpdatePatientCommandAdd_PatientShouldBeAddedToContext()
        {
            var fakeContext = A.Fake <DbContext>();
            var set         = new TestDbSet <Patient>();

            var patientId = Guid.NewGuid();

            var patientCommand = new AddUpdatePatientCommand()
            {
                PatientId        = patientId,
                ClinicalSystemId = "1",
                DateOfBirth      = new DateTime(1965, 01, 01),
                FirstName        = "David",
                LastName         = "Miller",
                GenderId         = 1,
                NhsNumber        = 123
            };

            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);
            A.CallTo(() => fakeContext.Set <Patient>()).Returns(set);

            _handler.Execute(patientCommand);

            set.Count(x => x.PatientId == patientId).Should().Be(1);

            var patient = set.First(x => x.PatientId == patientId);

            patient.PatientId.Should().Be(patientId);
            patient.ClinicalSystemId.Should().Be("1");
            patient.DateOfBirth.ShouldBeEquivalentTo(new DateTime(1965, 01, 01));
            patient.FirstName.Should().Be("David");
            patient.LastName.Should().Be("Miller");
            patient.GenderId.Should().Be(1);
            patient.NhsNumber.Should().Be(123);
        }
        public void Supplier_CreateNewSupplierValid_ContextCountOne()
        {
            var context    = new TestDbSet <Supplier>();
            var controller = new SupplierController(context);
            var result     = controller.Create(GetMockSupplier());

            Assert.AreEqual(1, context.Count());
        }
        public void RegUser_ShouldAddUser()
        {
            var users = new TestDbSet<User>();
            users.RegUser("ivan", "ivan");

            Assert.AreEqual(users.Count(), 1);
            Assert.AreEqual(users.FirstOrDefault().Name, "ivan");
        }
        public void Execute_GivenAddUpdateDisclaimerCommandUpdate_DisclaimerShouldBeUpdatedInContext()
        {
            var disclaimerId = Guid.NewGuid();

            var command = new AddUpdateDisclaimerCommand()
            {
                DisclaimerId = disclaimerId,
                IsAgreed = true
            };

            var fakeContext = A.Fake<DbContext>();
            var set = new TestDbSet<Disclaimer>() { new Disclaimer(){ DisclaimerId = disclaimerId} };

            A.CallTo(() => fakeContext.Set<Disclaimer>()).Returns(set);
            A.CallTo(() => _unitOfWork.Context).Returns(fakeContext);

            _handler.Execute(command);

            set.Count(x => x.DisclaimerId == disclaimerId).Should().Be(1);

            var disclaimer = set.First(x => x.DisclaimerId == disclaimerId);
            disclaimer.IsAgreed.Should().BeTrue();
        }
        public async Task TestToPagedQueryResultsExtension()
        {
            var list = new TestDbSet <PagedQueryResultsTestClass>();

            for (var i = 0; i < 10; i++)
            {
                list.Add(new PagedQueryResultsTestClass
                {
                    Id = i
                });
            }

            var start = 0;
            var limit = 1;
            Action <PagedQueryResults <PagedQueryResultsTestClass> > tester = (results) =>
            {
                Assert.AreEqual(list.Count(), results.Total);
                Assert.AreEqual(limit, results.Results.Count);
            };

            var queryable         = list.AsQueryable();
            var pagedResults      = queryable.ToPagedQueryResults(start, limit);
            var pagedResultsAsync = await queryable.ToPagedQueryResultsAsync(start, limit);
        }
        public void CreateParameter()
        {
            // Arrange
            int       ElementsCountBeforeAct = parametersDbSet.Count();
            Parameter parameter = new Parameter()
            {
                ParameterName        = "@added",
                ParameterRuName      = "added",
                ParameterCreatedDate = DateTime.Now
            };

            // Act
            repository.Create(parameter);

            // Assert
            Assert.AreNotEqual(ElementsCountBeforeAct, parametersDbSet.Count());
            Assert.IsTrue(parametersDbSet.Count() > ElementsCountBeforeAct);
            Assert.AreEqual("@added", parametersDbSet.Last().ParameterName);
        }
示例#9
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
                    );
            }
        }
示例#10
0
        public void GetAllQueries()
        {
            // Act
            IEnumerable <SqlQuery> queries = queryRepo.GetAll();

            // Assert
            Assert.AreEqual(queriesDbSet.Count(), queries.Count());
            Assert.AreEqual(
                queriesDbSet.First(),
                queries.First()
                );
            Assert.AreEqual(
                queriesDbSet.Last(),
                queries.Last()
                );
            Assert.AreEqual(
                queriesDbSet.First().SqlQueryName,
                queries.First().SqlQueryName
                );
        }
        public void GetAllQueryParameters_Test()
        {
            // Arrange
            int queryParametersCountBeforeAct = queryParametersDbSet.Count();

            // Act
            IEnumerable <SqlQueryParameter> queryParameters = queryParamRepo.GetAll();

            // Assert
            Assert.AreEqual(
                queryParametersCountBeforeAct,
                queryParameters.Count()
                );
            Assert.AreEqual(
                queryParametersCountBeforeAct,
                queryParametersDbSet.Count()
                );
            Assert.AreEqual(
                queryParametersDbSet.First().SqlQueryParameterId,
                queryParameters.First().SqlQueryParameterId
                );
        }
        public void GetAllOutputTables_Test()
        {
            // Arrange
            int tablesCount = tablesDbSet.Count();

            // Act
            IEnumerable <OutputTable> tables = outRepo.GetAll();

            // Assert
            Assert.AreEqual(tablesCount, tables.Count());
            Assert.AreEqual(tablesCount, tablesDbSet.Count());

            Assert.AreEqual(tables.First().OutputTableId, tablesDbSet.First().OutputTableId);
            Assert.AreEqual(tables.Last().FileName, tablesDbSet.Last().FileName);
        }