示例#1
0
        public void TypeDefinitionDataNameTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);

            AssertX.Equal(t.Name, typeData.Name, "The Name is not assigned correctly.");
        }
示例#2
0
        public void EnumerableSelectReturnsIEnumerable()
        {
            var array = Creator.New(() => new BasicTypes()).Array();

            var result = array.SelectNew <BasicTypes>();

            AssertX.AssignableFrom(result, typeof(IEnumerable <BasicTypes>));
        }
        public void MultiplePiecesOfMetadataAreCombinedIntoAnArray()
        {
            var cc = CreateContainer(typeof(MultipleNames));

            var withNames = cc.GetExport <Lazy <MultipleNames, MultiValuedName> >();

            AssertX.Equivalent(new[] { "A", "B", "B" }, withNames.Metadata.Name);
        }
示例#4
0
        public void QueryableSelectReturnsIQueryable()
        {
            var query = Creator.New(() => new BasicTypes()).Queryable();

            var result = query.SelectNew <BasicTypes>();

            AssertX.AssignableFrom(result, typeof(IQueryable <BasicTypes>));
        }
示例#5
0
        public void QueryableSelectReturnsIQueryable()
        {
            var query = Creator.New(() => new ObjectType()).Queryable();

            var result = query.SelectFields("Id");

            AssertX.AssignableFrom(result, typeof(IQueryable <object>));
        }
示例#6
0
            public void Add_ReturnsViewResult()
            {
                var subject = _fixture.Create <CanonicalSkillController>();

                var actionResult = subject.Add();

                AssertX.IsViewResult(actionResult);
            }
示例#7
0
        public void EnumerableSelectReturnsIEnumerable()
        {
            var array = Creator.New(() => new ObjectType()).Array();

            var result = array.SelectFields("Id");

            AssertX.AssignableFrom(result, typeof(IEnumerable <object>));
        }
示例#8
0
            public void Register_ReturnsAViewResult()
            {
                AccountController subject = _fixture.Create <AccountController>();

                ActionResult actionResult = subject.Register();

                AssertX.IsViewResultWithModelOfType <RegisterViewModel>(actionResult);
            }
示例#9
0
        public void FieldDataNameTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var field    = typeData.GetMember("FieldInstance");

            AssertX.Equal("FieldInstance", field.Name, "The Name of the member is incorrect.");
        }
示例#10
0
        public void FieldDataDeclaringTypeTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var field    = typeData.GetMember("FieldInstance");

            AssertX.Equal(typeData, field.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }
        public void OperatorDataNameTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var method   = typeData.GetMember("op_Addition");

            AssertX.Equal("op_Addition", method.Name, "The Name of the member is incorrect.");
        }
        public void OperatorDataDeclaringTypeTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var method   = typeData.GetMember("op_Addition");

            AssertX.Equal(typeData, method.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }
示例#13
0
            public async Task EditContactInfo_GivenIdForUserThatDoesntExist_Returns404()
            {
                _fakeEditContactInfoViewModelBuilder.Setup(x => x.BuildAsync(It.IsAny <int>())).Returns(Task.FromResult(null as EditContactInfoViewModel));
                ProfileController subject = _fixture.Create <ProfileController>();

                ActionResult actionResult = await subject.EditContactInfo(123);

                AssertX.Is404NotFoundResult(actionResult);
            }
示例#14
0
        public void IndexerDataDeclaringTypeTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var indexer  = typeData.GetMembers("Item")[0];

            AssertX.Equal(typeData, indexer.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }
示例#15
0
        private static void AssertIsExactInstanceOfInner(Type expectedType, Exception actual, int retryCount)
        {
            if (actual.InnerException == null)
                AssertX.Fail("Retry Count {0}: Expected '{1}' be the inner exception, however, it is null.", retryCount, expectedType);

            Type actualType = actual.InnerException.GetType();

            AssertX.Same(expectedType, actualType, "Retry Count {0}: Expected '{1}' to be the inner exception, however, '{2}' is.", retryCount, expectedType, actualType);
        }
示例#16
0
        private static void AssertIsExactInstanceOf(Type expectedType, Exception actual, int retryCount)
        {
            if (actual == null)
                AssertX.Fail("Retry Count {0}: Expected '{1}' to be thrown", retryCount, expectedType);

            Type actualType = actual.GetType();

            AssertX.Same(expectedType, actualType, "Retry Count {0}: Expected '{1}' to be thrown, however, '{2}' was thrown.", retryCount, expectedType, actualType);
        }
示例#17
0
            public void SignIn_ReturnsAViewResult()
            {
                _fakeHttpContext.Setup(x => x.Request.IsAuthenticated).Returns(false);
                AccountController subject = _fixture.Create <AccountController>();

                ActionResult actionResult = subject.SignIn();

                AssertX.IsViewResult(actionResult);
            }
示例#18
0
            public void SignOut_RedirectsTheUserToTheSignInPageWithFlashMessage()
            {
                AccountController subject = _fixture.Create <AccountController>();

                ActionResult actionResult = subject.SignOut();

                AssertX.FlashMessageSet(subject, "info", "You have been signed out.");
                AssertX.IsRedirectToRouteResult(actionResult, MVC.Account.Name, MVC.Account.ActionNames.SignIn);
            }
示例#19
0
            public async Task Edit_GivenIdOfSkillThatDoesntExist_ReturnsHttpNotFound()
            {
                _fakeSkillManager.Setup(x => x.LoadByIdAsync(1)).Returns(Task.FromResult(null as Skill));
                var subject = _fixture.Create <CanonicalSkillController>();

                var actionResult = await subject.Edit(1);

                AssertX.Is404NotFoundResult(actionResult);
            }
示例#20
0
    public static GameObject GetChild(this GameObject source, string name)
    {
        var sourceName = source.name;

        return(AssertX.One <GameObject>(
                   source.GetChildren(name),
                   $"Expected exactly one child named '{name}' in game object named '{sourceName}'."
                   ));
    }
示例#21
0
            public async Task Delete_GivenIdOfSkillThatDoesntExist_RedirectsToTheListPage()
            {
                _fakeSkillManager.Setup(x => x.LoadByIdAsync(456)).Returns(Task.FromResult(null as Skill));
                var subject = _fixture.Create <CanonicalSkillController>();

                var actionResult = await subject.Delete(456);

                AssertX.IsRedirectToRouteResult(actionResult, MVC.CanonicalSkill.Name, MVC.CanonicalSkill.ActionNames.List);
            }
示例#22
0
        public void IndexerDataNameTest()
        {
            var t        = typeof(TestClassDefinition);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var indexer  = typeData.GetMembers("Item")[0];

            AssertX.Equal("Item", indexer.Name, "The Name of the member is incorrect.");
        }
示例#23
0
            public async Task Add_GivenValidInput_RedirecstToTheListPageWithASuccessMessage()
            {
                var subject = _fixture.Create <CanonicalSkillController>();

                var actionResult = await subject.Add(_validInput);

                AssertX.FlashMessageSet(subject, "success", "C# was added.");
                AssertX.IsRedirectToRouteResult(actionResult, MVC.CanonicalSkill.Name, MVC.CanonicalSkill.ActionNames.List);
            }
示例#24
0
        public void ImportingOneWhereMultipleArePresentFails()
        {
            var c = CreateContainer(typeof(LogA), typeof(LogB), typeof(UsesLog));
            var x = AssertX.Throws <CompositionFailedException>(() =>
                                                                c.GetExport <UsesLog>());

            Assert.IsTrue(x.Message.Contains("LogA"));
            Assert.IsTrue(x.Message.Contains("LogB"));
        }
示例#25
0
        public void MissingDependencyMessageIsInformative()
        {
            var cc = CreateContainer(typeof(UserOfUnregistered));
            var x  = AssertX.Throws <CompositionFailedException>(() => cc.GetExport <UserOfUnregistered>());

            Assert.AreEqual("No export was found for the contract 'Unregistered'" + Environment.NewLine +
                            " -> required by import 'Unregistered' of part 'UserOfUnregistered'" + Environment.NewLine +
                            " -> required by initial request for contract 'UserOfUnregistered'", x.Message);
        }
示例#26
0
            public async Task EditContactInfo_GivenIdNotForCurrentUser_ReturnsUnauthorized()
            {
                SetLoggedInUserId(456);
                ProfileController subject = _fixture.Create <ProfileController>();

                ActionResult actionResult = await subject.EditContactInfo(123);

                AssertX.IsRedirectToRestrictedPage(actionResult);
            }
示例#27
0
        public void CardinalityViolationMessageIsInformative()
        {
            var cc = CreateContainer(typeof(ShouldBeOne), typeof(ButThereIsAnother), typeof(RequiresOnlyOne));
            var x  = AssertX.Throws <CompositionFailedException>(() => cc.GetExport <RequiresOnlyOne>());

            Assert.AreEqual("Only one export for the contract 'ShouldBeOne' is allowed, but the following parts: 'ButThereIsAnother', 'ShouldBeOne' export it." + Environment.NewLine +
                            " -> required by import 'One' of part 'RequiresOnlyOne'" + Environment.NewLine +
                            " -> required by initial request for contract 'RequiresOnlyOne'", x.Message);
        }
        public void OperatorDataParametersTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var method   = (OperatorData)typeData.GetMember("op_Addition");

            AssertX.Equal(2, method.Parameters.Count, "The public method has the wrong number of parameters.");
        }
示例#29
0
        public void PropertyDataDeclaringTypeTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var member   = (PropertyData)typeData.GetMember("PropertyReadOnly");

            AssertX.Equal(typeData, member.ContainingType, "The DeclaringType of a member should be the type in which it is defined.");
        }
        public void OperatorDataAccessibilityTest()
        {
            var t        = typeof(VariousMemberFeatures);
            var context  = MetadataResolutionContext.CreateFromTypes(t);
            var typeData = context.GetTypeDefinitionData(t);
            var member   = typeData.GetMember("op_Addition");

            AssertX.Equal(Accessibility.Public, member.Accessibility, "Incorrect Accessibility");
        }