public void TestInit()
        {
            #region User members

            _members = new List<User>
                    {
                        new User
                        {
                            UserId = 1,
                            UserName = "******"
                        },
                        new User
                        {
                            UserId = 2,
                            UserName = "******"
                        },
                        new User
                        {
                            UserId = 3,
                            UserName = "******"
                        }
                    };

            #endregion

            #region Communities

            _communities = new List<Community>
                     {
                         new Community
                         {
                             Id = 1,
                             LeaderUserId = 1,
                             Leader = _members.FirstOrDefault(a => a.UserId == 1),
                             Members = _members.ToList()
                         },
                         new Community
                         {
                             Id = 2,
                             LeaderUserId = 2,
                             Leader = _members.FirstOrDefault(a => a.UserId == 2),
                             Members = _members.ToList()
                         },
                         new Community
                         {
                             Id = 3,
                             LeaderUserId = 3,
                             Leader = _members.FirstOrDefault(a => a.UserId == 3),
                             Members = _members.ToList()
                         },
                     };

            #endregion
        }
        public void TryValidateObjectRecursive_returns_errors_when_grandchild_class_has_invalid_properties()
        {
            var parent = new Parent { PropertyA = 1, PropertyB = 1 };
            parent.Child = new Child { PropertyA = 1, PropertyB = 1 };
            parent.Child.GrandChildren = new [] {new GrandChild{PropertyA = 11, PropertyB = 11}};
            var validationResults = new List<ValidationResult>();

            var result = _validator.TryValidateObjectRecursive(parent, validationResults);

            Assert.IsFalse(result);
            Assert.AreEqual(2, validationResults.Count);
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "GrandChild PropertyA not within range"));
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "GrandChild PropertyB not within range"));
        }
示例#3
0
        public void ToListReturnsNewInstance()
        {
            List<int> integers = new List<int>() { 1, 2, 3 };
            List<int> result = integers.ToList();

            Assert.That(result, Is.Not.SameAs(integers));
        }
        public static void PrintSingleTest()
        {
            var directories = GetBuildDirectories();

            var tests = new List<TestResult>();

            foreach (var dir in directories)
            {
                var files = Directory.GetFiles(dir, "junitResult.xml");
                if (files.Any())
                {
                    var fileName = files[0];
                    var iterator = GetTestCasesWithErrors("UserAcceptanceTests.Features.ProductFeature","RefreshOnProductAfterAddingCommentShouldNOTResultInErrorBugFix",fileName);

                    while (iterator.MoveNext())
                    {
                        var failingTest = GetFailingTestName(iterator);

                        var testResult = new TestResult {BuildName = GetBuildName(dir),TestName = failingTest};

                        tests.Add(testResult);
                    }
                }

            }
            foreach (var failingTest in tests.ToList().OrderBy(x=>x.BuildName).Reverse())
            {
                Console.WriteLine(failingTest);
            }
        }
示例#5
0
        public void ResultIsIndependentOfSource()
        {
            List<string> source = new List<string> { "xyz", "abc" };
            List<string> result = source.ToList();
            result.AssertSequenceEqual("xyz", "abc");
            Assert.AreNotSame(source, result);

            source.Add("extra element");
            // The extra element hasn't been added to the result
            Assert.AreNotEqual(source.Count, result.Count);
        }
示例#6
0
        public void Setup()
        {
            var reviews = new List<Review>();
               
            var review = new Review();
            review.Id = 1;
            review.Title = "Testing";
            review.Content = "Testng Reviews";
            review.UserId = "d9274a62-8a8c-46bf-aedc-d1cb3e8626c0";
            review.Username = "******";

            reviews.Add(review);

            this.Reviews = reviews.ToList();
        }
        public void CombinesDataBlocks(
            [Values(100, 500, 1000, 5000)] double blockMilliseconds,
            [Values(5000, 10000)] double sampleRateHz,
            [Values(1, 4)] int numStim
            )
        {
            var parameters = new Dictionary<string, object>();
            var sampleRate = new Measurement((decimal)sampleRateHz, "Hz");

            var data = new List<IOutputData>();
            var stimuli = new List<IStimulus>();
            for (int i = 0; i < numStim; i++)
            {
                IOutputData d = new OutputData(Enumerable.Range(0, (int)TimeSpan.FromSeconds(3).Samples(new Measurement((decimal)sampleRateHz, "Hz")))
                    .Select(j => new Measurement(j, "units")).ToList(),
                    sampleRate,
                    false);
                data.Add(d);
                stimuli.Add(new RenderedStimulus((string)"RenderedStimulus" + i, (IDictionary<string, object>)parameters, d));
            }

            var combined = new CombinedStimulus("CombinedStimulus", new Dictionary<string, object>(),  stimuli, CombinedStimulus.Add);

            var blockSpan = TimeSpan.FromMilliseconds(blockMilliseconds);
            IEnumerator<IOutputData> iter = combined.DataBlocks(blockSpan).GetEnumerator();
            while (iter.MoveNext())
            {
                IOutputData expectedData = null;
                foreach (var d in data.ToList())
                {
                    var cons = d.SplitData(blockSpan);
                    data[data.IndexOf(d)] = cons.Rest;

                    expectedData = expectedData == null
                        ? cons.Head
                        : expectedData.Zip(cons.Head, (m1, m2) => new Measurement(m1.QuantityInBaseUnits + m2.QuantityInBaseUnits, 0, m1.BaseUnits));
                }

                Assert.That(iter.Current.Duration, Is.EqualTo(expectedData.Duration));
                Assert.That(iter.Current.Data, Is.EqualTo(expectedData.Data));
            }
        }
示例#8
0
文件: AstTests.cs 项目: SealedSun/prx
        public void DeterminePlaceholderIndicesNormalTets()
        {
            //(?,?2,?,?2,?1)
            var placeholders = new List<AstPlaceholder>
                {
                    _createPlaceholder(),
                    _createPlaceholder(1),
                    _createPlaceholder(),
                    _createPlaceholder(1),
                    _createPlaceholder(0)
                };

            var copy = placeholders.ToList();
            Assert.AreNotSame(copy, placeholders);

            AstPlaceholder.DeterminePlaceholderIndices(placeholders);

            //First assert that the list itself has not been altered
            Assert.AreEqual(placeholders.Count, copy.Count);
            for (var i = 0; i < placeholders.Count; i++)
                Assert.AreSame(copy[i], placeholders[i], "List itself must not be altered.");

            //Expexted mapping (0-based):
            //  ?2, ?1, ?3, ?1, ?0
            foreach (var placeholder in placeholders)
                Assert.IsTrue(placeholder.Index.HasValue,
                    "All placeholders should be assigned afterwards.");

            // ReSharper disable PossibleInvalidOperationException
            Assert.AreEqual(2, placeholders[0].Index.Value,
                "Placeholder at source position 0 is not mapped correctly");
            Assert.AreEqual(1, placeholders[1].Index.Value,
                "Placeholder at source position 1 is not mapped correctly");
            Assert.AreEqual(3, placeholders[2].Index.Value,
                "Placeholder at source position 2 is not mapped correctly");
            Assert.AreEqual(1, placeholders[3].Index.Value,
                "Placeholder at source position 3 is not mapped correctly");
            Assert.AreEqual(0, placeholders[4].Index.Value,
                "Placeholder at source position 4 is not mapped correctly");
            // ReSharper restore PossibleInvalidOperationException
        }
        public async void Index_Returns_Category_List()
        {
            // Arrange   
            IEnumerable<Category> fakeCategories = new List<Category>
            {
                new Category {Id = 1, Name = "Test1", Description = "Test1Desc"},
                new Category {Id = 2, Name = "Test2", Description = "Test2Desc"},
                new Category {Id = 3, Name = "Test3", Description = "Test3Desc"}
            }.AsEnumerable();
            _firstDbContextUoW.Setup(x => x.CategoryRepository.GetAllAsync()).ReturnsAsync(fakeCategories.ToList());
            var controller = new CategoryController(_categoryService);

            // Act
            Mapper.CreateMap<Category, CategoryModel>();
            var result = (ViewResult) await controller.Index();
            // Assert
            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(IEnumerable<CategoryModel>),
                result.ViewData.Model, "Wrong View Model");
            var categories = result.ViewData.Model as IEnumerable<CategoryModel>;
            if (categories != null) Assert.AreEqual(3, categories.Count(), "Got wrong number of Categories");
        }
        public async void Index_Returns_Department_List()
        {
            // Arrange   
            IEnumerable<Department> fakeDepartments = new List<Department>
            {
                new Department {Id = 1, Name = "Test1"},
                new Department {Id = 2, Name = "Test2"},
                new Department {Id = 3, Name = "Test3"}
            }.AsEnumerable();
            _secondDbContextUoW.Setup(x => x.DepartmentRepository.GetAllAsync()).ReturnsAsync(fakeDepartments.ToList());
            var controller = new DepartmentController(_departmentService);

            // Act
            Mapper.CreateMap<Department, DepartmentModel>();
            var result = (ViewResult) await controller.Index();
            // Assert
            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(IEnumerable<DepartmentModel>),
                result.ViewData.Model, "Wrong View Model");
            var departments = result.ViewData.Model as IEnumerable<DepartmentModel>;
            if (departments != null) Assert.AreEqual(3, departments.Count(), "Got wrong number of Departments");
        }
示例#11
0
            public void FillInGuestPhonesCallsDaoOnce()
            {
                var guestPhoneDao = new Mock<IGuestPhoneDao>();
                BookingDao bookingDao = new BookingDao
                    {
                        GuestPhoneDao = guestPhoneDao.Object
                    };
                IEnumerable<Booking> bookings = new List<Booking>()
                    {
                        new Booking
                        {
                            GuestId = 1,
                            Guest = new Guest() { GuestId = 1 }
                        },
                        new Booking
                        {
                            GuestId = 2,
                            Guest = new Guest() { GuestId = 1 }
                        }
                    };

                guestPhoneDao.Setup(gp => gp.GetAllByGuestIdList(It.IsAny<IEnumerable<int>>()))
                             .Returns(new List<GuestPhone>()
                                 {
                                     new GuestPhone {GuestId = 1},
                                     new GuestPhone {GuestId = 2}
                                 });

                bookingDao.FillInGuestPhones(bookings);

                Assert.IsTrue(bookings.ToList().TrueForAll(b => b.Guest.GuestPhones != null),
                              "Not all booking got phone numbers correctly");
                guestPhoneDao.Verify(gp => gp.GetAllByGuestIdList(It.IsAny<IEnumerable<int>>()), Times.Once);
            }
示例#12
0
        public void Given_a_FRA_when_copy_then_attached_documents_are_cloned()
        {

            var currentUser = new UserForAuditing { Id = Guid.NewGuid() };
            IEnumerable<RiskAssessmentDocument> documents = new List<RiskAssessmentDocument>()
                                                     {
                                                          new RiskAssessmentDocument()
                                                             {
                                                                 Id = 1, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234),Description = "doc description",DocumentLibraryId = 123
                                                             },
                                                         new RiskAssessmentDocument()
                                                             {
                                                                 Id = 2, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234)
                                                             }
                                                         ,
                                                         new RiskAssessmentDocument()
                                                             {
                                                                 Id = 3, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234) 
                                                             }
                                                     };
            var fraToCopy = FireRiskAssessment.Create("this is the title", "the ref", 1312, null, new UserForAuditing { Id = Guid.NewGuid() });
            fraToCopy.Documents = documents.ToList();

            //when
            var copiedFra = fraToCopy.Copy(currentUser);

            //then
            Assert.AreEqual(fraToCopy.Documents.Count(), copiedFra.Documents.Count);

            Assert.IsTrue(copiedFra.Documents.All(x => x.Id == 0));
            Assert.IsTrue(copiedFra.Documents.All(x => x.CreatedBy.Id == currentUser.Id)); //ensure that all cloned are new entities
            Assert.IsTrue(copiedFra.Documents.All(x => x.CreatedOn.Value.Date == DateTime.Now.Date)); //ensure that all cloned are new entities
            Assert.IsTrue(copiedFra.Documents.Any(x => x.Description == documents.First().Description));

            Assert.AreEqual(fraToCopy, copiedFra.Documents.First().RiskAssessment);
        }
示例#13
0
 public string Print(List<Token> tokens)
 {
     IntrospectedTokens = tokens.ToList();
     return "The result of this outputter is found in the field 'IntrospectedTokens'";
 }
示例#14
0
        public void testBuildPatientObject()
        {
            DemographicSet patientDemogs = new DemographicSet();
            Address addr = new Address() { City = "Hooville", State = "MI", County = "Eggs and Ham", Street1 = "123 Elm St.", Street2 = "Apt 4", Zipcode = "90210" };
            PhoneNum phone = new PhoneNum() { Description = "Cell phone", AreaCode = "555", Exchange = "867", Number = "5309" };
            EmailAddress email = new EmailAddress() { Address = "*****@*****.**" };
            IList<Address> addresses = new List<Address>() { addr };
            IList<PhoneNum> telephones = new List<PhoneNum>() { phone };
            IList<EmailAddress> emails = new List<EmailAddress>() { email };
            patientDemogs.EmailAddresses = emails.ToList<EmailAddress>();
            patientDemogs.PhoneNumbers = telephones.ToList<PhoneNum>();
            patientDemogs.StreetAddresses = addresses.ToList<Address>();

            CCRHelper helper = new CCRHelper();
            ActorType patient = helper.buildPatientObject("1234567890", "987654321", "USER", "ONE", "O", "0000/12/25", "2011", "M", patientDemogs);

            Assert.IsNotNull(patient);
            Assert.IsTrue(patient.Item is ActorTypePerson);
            Assert.AreEqual(patient.Address.Count, 1);
            Assert.AreEqual(patient.EMail.Count, 1);
            Assert.AreEqual(patient.Telephone.Count, 1);
            Assert.AreEqual(patient.IDs.Count, 2);

            Assert.IsTrue(String.Equals(patient.IDs[0].ID, "1234567890"));
            Assert.IsTrue(String.Equals(patient.IDs[0].Type.Text, "ID"));
            Assert.IsTrue(String.Equals(patient.IDs[1].ID, "987654321"));
            Assert.IsTrue(String.Equals(patient.IDs[1].Type.Text, "SSN"));
            Assert.IsTrue(String.Equals(patient.Address[0].City, "Hooville"));
            Assert.IsTrue(String.Equals(patient.Address[0].County, "Eggs and Ham"));
            Assert.IsTrue(String.Equals(patient.Address[0].Line1, "123 Elm St."));
            Assert.IsTrue(String.Equals(patient.Address[0].Line2, "Apt 4"));
            Assert.IsTrue(String.Equals(patient.Address[0].PostalCode, "90210"));
            Assert.IsTrue(String.Equals(patient.Address[0].State, "MI"));
            Assert.IsTrue(String.Equals(patient.EMail[0].Value, "*****@*****.**"));
            Assert.IsTrue(String.Equals(patient.Telephone[0].Value, "5558675309"));

            ActorTypePerson person = (ActorTypePerson)patient.Item;
            Assert.IsTrue(String.Equals(person.DateOfBirth.ExactDateTime, "0000/12/25"));
            Assert.IsTrue(String.Equals(person.DateOfBirth.Age.Value, "2011"));
            Assert.IsTrue(String.Equals(person.Gender.Text, "M"));
            Assert.IsTrue(String.Equals(person.Name.CurrentName.Family.First(), "ONE"));
            Assert.IsTrue(String.Equals(person.Name.CurrentName.Given.First(), "USER"));
            Assert.IsTrue(String.Equals(person.Name.CurrentName.Middle.First(), "O"));
        }
        public void Should_clear_all_cache_strategies()
        {
            var controllerName = NameHelper.Controller<AdminController>();
            var policyContainers = new List<PolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast<IPolicyContainerConfiguration>().ToList());
            conventionPolicyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);

            // Act
            conventionPolicyContainer.ClearCacheStrategies();

            // Assert
            var containers = policyContainers.ToList();
            Assert.That(containers[0].CacheStrategies.Any(), Is.False);
            Assert.That(containers[1].CacheStrategies.Any(), Is.False);
            Assert.That(containers[2].CacheStrategies.Any(), Is.False);
        }
        public void GetTeacherCourses_ReturnCourses()
        {
            // Arrange
            int userId = 8;
            Course expected = new Course
            {
                OwnerId = userId,
                WordSuites = new List<WordSuite>()
                    { 
                        new WordSuite
                        {

                            PrototypeId = null
                        }
                    },
                Language = new Language(),
               
            };
            IQueryable<Course> courses = new List<Course>
            {
                expected
            }.AsQueryable<Course>();
            Mock<IRepository<WorldOfWords.Domain.Models.Course>> repo = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.CourseRepository).Returns(repo.Object);
            repo.Setup(x => x.GetAll()).Returns(courses);
            
            //Act
            var actual = _service.GetTeacherCourses(userId);

            //Assert
            _uow.Verify(x => x.CourseRepository, Times.Once);
            _factory.Verify(x => x.GetUnitOfWork(), Times.Once);
            repo.Verify(x => x.GetAll(), Times.Once);
            Assert.AreEqual(courses.ToList<Course>(), actual);
        }
示例#17
0
        public IEnumerable<Input> Parse(string value)
        {
            bool isEscape;
            ParseState state = ParseState.None;
            var buffer = new StringBuilder();
            string currentName = string.Empty;
            List<string> currentValues = new List<string>();
            List<Input> inputs = new List<Input>();
            char currentQuote = '\0';
            Action commitName = () =>
            {
                currentName = buffer.ToString();
                buffer = new StringBuilder();
                state = ParseState.BeforeValue;
            };
            Action commitValue = () =>
            {
                if (buffer.Length > 0)
                    currentValues.Add(buffer.ToString());
                buffer = new StringBuilder();
                state = ParseState.AfterValue;
            };
            Action commitInput = () =>
            {
                if ((currentValues.Count == 0 && currentName == string.Empty) == false)
                {
                    if (currentValues.Count == 0)
                        inputs.Add(new SingleValueInput { Name = currentName, Value = string.Empty });
                    else if (currentValues.Count == 1)
                        inputs.Add(new SingleValueInput { Name = currentName, Value = currentValues[0] });
                    else
                        inputs.Add(new MultiValueInput { Name = currentName, Values = currentValues.ToList() });
                }
                currentName = string.Empty;
                state = ParseState.None;
                currentValues.Clear();
            };
            Action<char> appendCharacter = character =>
            {

                if (state == ParseState.BeforeValue || state == ParseState.None)
                    state = ParseState.Value;
                if (state == ParseState.AfterValue)
                {
                    commitValue();
                    commitInput();
                    state = ParseState.Value;
                }
                buffer.Append(character);

            };
            for (var position = 0; position < value.Length; position++)
            {
                var current = value[position];

                if (current == DBL_QUOTE || current == SINGLE_QUOTE)
                {
                    if (state == ParseState.BeforeValue || state == ParseState.None)
                    {
                        currentQuote = current;
                        state = ParseState.QuotedValue;
                        continue;
                    }
                    if (state == ParseState.QuotedValue && current == currentQuote)
                    {
                        currentQuote = '\0';
                        commitValue();
                        continue;
                    }
                }
                if (current == '`')
                {
                    if (value.Length - (position + 1) == 0) throw new InputParserException("Incomplete command. The escape character '`' is at the end of the line.");

                    var c = value[++position];
                    appendCharacter(ConvertToSpecialCharacter(c));

                    continue;
                }
                if (current == '-' && state == ParseState.None)
                {
                    state = ParseState.Name;
                    continue;
                }

                if (current == '-' && (state == ParseState.AfterValue || state ==ParseState.BeforeValue))
                {
                    commitInput();
                    state = ParseState.Name;
                    continue;
                }
                if (current == ',' && (state == ParseState.Value || state == ParseState.AfterValue))
                {
                    commitValue();
                    state = ParseState.BeforeValue;
                    continue;
                }
                if (char.IsWhiteSpace(current))
                {
                    if (state == ParseState.Name)
                    {
                        commitName();
                        state = ParseState.BeforeValue;
                    }
                    else if (state == ParseState.Value)
                    {
                        state = ParseState.AfterValue;
                        commitValue();
                    }
                    else if (state == ParseState.QuotedValue)
                        buffer.Append(current);

                    continue;
                }
                if (state == ParseState.Name)
                {
                    if (IsNameCharacter(current))
                    {
                        buffer.Append(current);
                        continue;
                    }
                }
                appendCharacter(current);
            }
            if (buffer.Length > 0 &&
                (state == ParseState.Value ||
                 state == ParseState.None ||
                 state == ParseState.AfterValue))
            {
                commitValue();
            }
            else if (buffer.Length > 0 && state == ParseState.Name)
                commitName();
            commitInput();
            return inputs;
        }
        public void TryValidateObject_when_missing_required_properties_returns_errors()
        {
            var parent = new Parent { PropertyA = null, PropertyB = null };
            var validationResults = new List<ValidationResult>();

            var result = _validator.TryValidateObject(parent, validationResults);

            Assert.IsFalse(result);
            Assert.AreEqual(2, validationResults.Count);
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "Parent PropertyA is required"));
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "Parent PropertyB is required"));
        }
示例#19
0
        public void ToList_ReturnsNewInstance()
        {
            // Assemble
            List<int> original = new List<int>();

            // Act
            var actual = original.ToList();

            // Assert
            actual.Should().NotBeSameAs(original);
        }
        public void TryValidateObject_includes_errors_from_all_objects()
        {
            var parent = new Parent { PropertyA = 5, PropertyB = 6 };
            parent.Child = new Child { PropertyA = 5, PropertyB = 6 };
            parent.Child.GrandChildren = new[] { new GrandChild { PropertyA = 5, PropertyB = 6 } };
            var validationResults = new List<ValidationResult>();

            var result = _validator.TryValidateObjectRecursive(parent, validationResults);

            Assert.IsFalse(result);
            Assert.AreEqual(3, validationResults.Count);
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "Parent PropertyA and PropertyB cannot add up to more than 10"));
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "Child PropertyA and PropertyB cannot add up to more than 10"));
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "GrandChild PropertyA and PropertyB cannot add up to more than 10"));
        }
        public void TryValidateObject_calls_grandchild_IValidatableObject_method()
        {
            var parent = new Parent { PropertyA = 1, PropertyB = 1 };
            parent.Child = new Child { PropertyA = 1, PropertyB = 1 };
            parent.Child.GrandChildren = new[] { new GrandChild { PropertyA = 5, PropertyB = 6 } };
            var validationResults = new List<ValidationResult>();

            var result = _validator.TryValidateObjectRecursive(parent, validationResults);

            Assert.IsFalse(result);
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "GrandChild PropertyA and PropertyB cannot add up to more than 10"));
        }
        [Test] //work +
        //старт інтервал має починатись з 0, як і елементи колекції
        public void GetUsersFromIntervalByRoleId_IsRoleZero_Test()
        {
            //Arrange
            Role admin = new Role();
            admin.Id = 0;

            IQueryable<Role> rol = new List<Role>()
            {
                admin
            }.AsQueryable<Role>();

            IQueryable<User> listOfUsers = new List<User>
                            {
                                new User{Id = 5, Name = "Andrew", Roles = new List<Role>(){admin}}, 
                                new User{Id = 3, Name = "Fred", Roles = new List<Role>(){admin}},
                                new User{Id = 1, Name = "Sasha", Roles = new List<Role>(){admin}}

                            }.AsQueryable<User>();

            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(listOfUsers);

            //Act
            var result = usServ.GetUsersFromIntervalByRoleId(0, 3);

            //Assert
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Exactly(3));
            userReposit.Verify(t => t.GetAll(), Times.Exactly(3));
            Assert.AreEqual(result, listOfUsers.ToList<User>());

        }
        public void Should_add_policyresult_cache_strategy_to_policycontainers()
        {
            // Arrange
            var controllerName = NameHelper.Controller<AdminController>();
            var policyContainers = new List<PolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast<IPolicyContainerConfiguration>().ToList(), By.Controller);
            const Cache expectedLifecycle = Cache.PerHttpRequest;
            var expectedType = typeof(DenyAnonymousAccessPolicy);

            // Act
            conventionPolicyContainer.Cache<DenyAnonymousAccessPolicy>(expectedLifecycle);

            // Assert
            var containers = policyContainers.ToList();
            Assert.That(containers[0].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[0].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[0].CacheStrategies.Single().CacheLevel, Is.EqualTo(By.Controller));
            Assert.That(containers[1].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[1].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[1].CacheStrategies.Single().CacheLevel, Is.EqualTo(By.Controller));
            Assert.That(containers[2].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[2].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[2].CacheStrategies.Single().CacheLevel, Is.EqualTo(By.Controller));
        }
示例#24
0
文件: AstTests.cs 项目: SealedSun/prx
        public void RemoveRedundant1()
        {
            const string file = "THE_FILE";
            const int line = 666;
            const int col = 555;
            //test case from MissingMapped
            var subject = new AstNull(file, line, col);
            var argv = new List<AstExpr>
                {
                    subject,
                    _createPlaceholder(1),
                    _createPlaceholder(2)
                };
            var originalArgv = argv.ToList();

            _placeholderArgvProcessing(argv);

            Assert.AreEqual(3, argv.Count, "argc changed");
            for (var i = 0; i < argv.Count; i++)
                Assert.AreSame(originalArgv[i], argv[i]);
        }
示例#25
0
        /// <summary>
        ///     Parsers the ClustalW file for different test cases based
        ///     on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        private void ParserGeneralTestCases(string nodeName, AdditionalParameters addParam)
        {
            // Gets the Filename
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);

            Assert.IsFalse(string.IsNullOrEmpty(filePath));
            ApplicationLog.WriteLine(string.Format("ClustalW Parser BVT: Reading the File from location '{0}'", filePath));

            // Get the range list after parsing.
            var parserObj = new ClustalWParser();

            IEnumerable<ISequenceAlignment> sequenceAlignmentList = null;
            ISequenceAlignment sequenceAlignment = null;

            // Gets the SequenceAlignment list based on the parameters.
            switch (addParam)
            {
                case AdditionalParameters.Parse:
                    sequenceAlignmentList = parserObj.Parse(filePath).ToList();
                    break;
                case AdditionalParameters.ParseOne:
                    sequenceAlignment = parserObj.ParseOne(filePath);
                    break;
                case AdditionalParameters.ParseTextReader:
                    using (var strRdrObj = File.OpenRead(filePath))
                    {
                        sequenceAlignmentList = parserObj.Parse(strRdrObj).ToList();
                    }
                    break;
                case AdditionalParameters.ParseOneTextReader:
                    using (var strRdrObj = File.OpenRead(filePath))
                    {
                        sequenceAlignment = parserObj.ParseOne(strRdrObj);
                    }
                    break;
                default:
                    break;
            }

            // Gets all the expected values from xml.
            XElement expectedAlignmentNodes = utilityObj.xmlUtil.GetNode(nodeName, Constants.ExpectedAlignmentNode);
            IList<XNode> nodes = expectedAlignmentNodes.Nodes().ToList();

            //Get all the values from the elements in the node.
            var expectedAlignmentObj = new Dictionary<string, string>();
            foreach (XElement node in nodes)
            {
                expectedAlignmentObj[node.Name.ToString()] = node.Value;
            }

            //Create a ISequenceAlignment List
            switch (addParam)
            {
                case AdditionalParameters.ParseOne:
                case AdditionalParameters.ParseOneTextReader:
                    sequenceAlignmentList = new List<ISequenceAlignment>() { sequenceAlignment };
                    break;
                default:
                    break;
            }

            var expectedAlignmentList = new List<Dictionary<string, string>> { expectedAlignmentObj };

            Assert.IsTrue(CompareOutput(sequenceAlignmentList.ToList(), expectedAlignmentList));
            ApplicationLog.WriteLine("ClustalW Parser BVT: Successfully validated all the Alignment Sequences");
        }
示例#26
0
        public void Given_a_FRA_when_copy_then_fire_safety_control_measures_are_cloned()
        {
            //given
            var currentUser = new UserForAuditing { Id = Guid.NewGuid() };
            var fraToCopy = FireRiskAssessment.Create("this is the title", "the ref", 1312, null, new UserForAuditing { Id = Guid.NewGuid() });

            IEnumerable<FireRiskAssessmentControlMeasure> fireSafetyControlMeasures = new List<FireRiskAssessmentControlMeasure>()
                                                     {
                                                         new FireRiskAssessmentControlMeasure
                                                             {
                                                          FireSafetyControlMeasure = new FireSafetyControlMeasure()
                                                             {
                                                                 Id = 1, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234),Name = "toxic air events"
                                                             },
                                                             RiskAssessment = fraToCopy
                                                             },
                                                         new FireRiskAssessmentControlMeasure
                                                             {
                                                          FireSafetyControlMeasure = new FireSafetyControlMeasure()
                                                             {
                                                                 Id = 2, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234)
                                                             },
                                                             RiskAssessment = fraToCopy
                                                             },
                                                         new FireRiskAssessmentControlMeasure
                                                             {
                                                          FireSafetyControlMeasure = new FireSafetyControlMeasure()
                                                             {
                                                                 Id = 3, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234) 
                                                             },
                                                             RiskAssessment = fraToCopy
                                                             },
                                                     };

            fraToCopy.FireSafetyControlMeasures = fireSafetyControlMeasures.ToList();

            //when
            var copiedFra = fraToCopy.Copy(currentUser);

            //then
            Assert.AreEqual(fraToCopy.FireSafetyControlMeasures.Count(), copiedFra.FireSafetyControlMeasures.Count);

        }
示例#27
0
        public void Given_a_FRA_when_copy_then_people_at_risk_are_cloned()
        {
            //given
            var currentUser = new UserForAuditing { Id = Guid.NewGuid() };
            IEnumerable<RiskAssessmentPeopleAtRisk> peopleAtRisk = new List<RiskAssessmentPeopleAtRisk>()
                                                     {
                                                         new RiskAssessmentPeopleAtRisk
                                                             {
                                                                 PeopleAtRisk = new PeopleAtRisk()
                                                                 {
                                                                     Id = 1, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234)
                                                                 }
                                                             },
                                                         new RiskAssessmentPeopleAtRisk
                                                             {
                                                                 PeopleAtRisk = new PeopleAtRisk()
                                                                 {
                                                                     Id = 2, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234)
                                                                 }
                                                             },
                                                         new RiskAssessmentPeopleAtRisk
                                                             {
                                                                 PeopleAtRisk = new PeopleAtRisk()
                                                                 {
                                                                     Id = 3, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234) 
                                                                 }
                                                             }
                                                     };
            var fraToCopy = FireRiskAssessment.Create("this is the title", "the ref", 1312, null, new UserForAuditing { Id = Guid.NewGuid() });
            fraToCopy.PeopleAtRisk = peopleAtRisk.ToList(); // .AttachPeopleAtRiskToRiskAssessment(peopleAtRisk,currentUser);

            //when
            var copiedFra = fraToCopy.Copy(currentUser);

            //then
            Assert.IsTrue(copiedFra.PeopleAtRisk.Count == fraToCopy.PeopleAtRisk.Count());

        }
 public void WithAttribute_EmptyList_ReturnsEmptyList()
 {
     var list = new List<Type>().WithAttribute<CustomTestAttribute>();
     Assert.That(() => list.ToList(), Has.Count.EqualTo(0));
 }
示例#29
0
        public void ToList_AddingToList_DoesNotUpdateOriginalList()
        {
            // Assemble
            List<int> numbers = new List<int> { 1, 2, 4 };
            List<int> expected = new List<int> { 1, 2, 4 };

            // Act
            numbers.ToList().Add(5);

            // Assert
            CollectionAssert.AreEquivalent(expected, numbers);
        }
示例#30
0
        public void Given_a_FRA_when_copy_then_sources_of_fuel_are_cloned()
        {
            //given
            var currentUser = new UserForAuditing { Id = Guid.NewGuid() };
            var fraToCopy = FireRiskAssessment.Create("this is the title", "the ref", 1312, null, new UserForAuditing { Id = Guid.NewGuid() });

            IEnumerable<FireRiskAssessmentSourceOfFuel> sourcesOfFuel = new List<FireRiskAssessmentSourceOfFuel>()
                                                                            {
                                                                                new FireRiskAssessmentSourceOfFuel
                                                                                    {
                                                                                        SourceOfFuel = new SourceOfFuel
                                                                                                           {
                                                                                                               Id = 1,
                                                                                                               CreatedBy
                                                                                                                   =
                                                                                                                   new UserForAuditing
                                                                                                                       {
                                                                                                                           Id
                                                                                                                               =
                                                                                                                               Guid
                                                                                                                               .
                                                                                                                               NewGuid
                                                                                                                               ()
                                                                                                                       },
                                                                                                               CreatedOn
                                                                                                                   =
                                                                                                                   DateTime
                                                                                                                   .Now.
                                                                                                                   AddDays
                                                                                                                   (-1234),
                                                                                                               Name =
                                                                                                                   "toxic air events"
                                                                                                           },
                                                                                        FireRiskAssessment = fraToCopy
                                                                                    },
                                                                                new FireRiskAssessmentSourceOfFuel
                                                                                    {
                                                                                        SourceOfFuel =
                                                                                            new SourceOfFuel()
                                                                                                {
                                                                                                    Id = 2,
                                                                                                    CreatedBy =
                                                                                                        new UserForAuditing
                                                                                                            {
                                                                                                                Id =
                                                                                                                    Guid
                                                                                                                    .
                                                                                                                    NewGuid
                                                                                                                    ()
                                                                                                            },
                                                                                                    CreatedOn =
                                                                                                        DateTime.Now.
                                                                                                        AddDays(-1234)
                                                                                                },
                                                                                        FireRiskAssessment = fraToCopy
                                                                                    },
                                                                                new FireRiskAssessmentSourceOfFuel
                                                                                    {
                                                                                        SourceOfFuel =
                                                                                            new SourceOfFuel()
                                                                                                {
                                                                                                    Id = 3,
                                                                                                    CreatedBy =
                                                                                                        new UserForAuditing
                                                                                                            {
                                                                                                                Id =
                                                                                                                    Guid
                                                                                                                    .
                                                                                                                    NewGuid
                                                                                                                    ()
                                                                                                            },
                                                                                                    CreatedOn =
                                                                                                        DateTime.Now.
                                                                                                        AddDays(-1234)
                                                                                                },
                                                                                        FireRiskAssessment = fraToCopy
                                                                                    }
                                                                            };
            fraToCopy.FireRiskAssessmentSourcesOfFuel = sourcesOfFuel.ToList();

            //when
            var copiedFra = fraToCopy.Copy(currentUser);

            //then
            Assert.AreEqual(fraToCopy.FireRiskAssessmentSourcesOfFuel.Count(), copiedFra.FireRiskAssessmentSourcesOfFuel.Count);

        }