示例#1
0
        public void NoSessionShouldThrowExceptionWithEntries()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services =>
            {
                services.AddMemoryCache();
                services.AddDistributedMemoryCache();
                services.AddSession();
            });

            Test.AssertException <DataProviderAssertionException>(
                () =>
            {
                MyViewComponent <AddSessionComponent>
                .InvokedWith(c => c.Invoke())
                .ShouldHave()
                .NoSession()
                .AndAlso()
                .ShouldReturn()
                .View();
            },
                "When invoking AddSessionComponent expected to have session with no entries, but in fact it had some.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
示例#2
0
        public void SessionWithNumberShouldThrowExceptionWithInvalidEntries()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services =>
            {
                services.AddMemoryCache();
                services.AddDistributedMemoryCache();
                services.AddSession();
            });

            Test.AssertException <DataProviderAssertionException>(
                () =>
            {
                MyViewComponent <NormalComponent>
                .InvokedWith(c => c.Invoke())
                .ShouldHave()
                .Session(1)
                .AndAlso()
                .ShouldReturn()
                .View();
            },
                "When invoking NormalComponent expected to have session with 1 entry, but in fact contained 0.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void WithEntitiesShouldSetupDbContext()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services =>
            {
                services.AddDbContext <CustomDbContext>(options =>
                                                        options.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=TestDb;Trusted_Connection=True;MultipleActiveResultSets=true;Connect Timeout=30;"));
            });

            MyViewComponent <FindDataComponent>
            .Instance()
            .WithData(data => data
                      .WithEntities <CustomDbContext>(db => db
                                                      .Models.Add(new CustomModel
            {
                Id   = 1,
                Name = "Test"
            })))
            .InvokedWith(c => c.Invoke(1))
            .ShouldReturn()
            .View(view => view
                  .WithModelOfType <CustomModel>()
                  .Passing(m => m.Name == "Test"));

            MyViewComponent <FindDataComponent>
            .Instance()
            .WithData(data => data
                      .WithEntities(db => db.Add(new CustomModel
            {
                Id   = 1,
                Name = "Test"
            })))
            .InvokedWith(c => c.Invoke(1))
            .ShouldReturn()
            .View(view => view
                  .WithModelOfType <CustomModel>()
                  .Passing(m => m.Name == "Test"));

            MyViewComponent <FindDataComponent>
            .Instance()
            .WithData(data => data
                      .WithEntities <CustomDbContext>(db => db
                                                      .Models.Add(new CustomModel
            {
                Id   = 2,
                Name = "Test"
            })))
            .InvokedWith(c => c.Invoke(1))
            .ShouldReturn()
            .Content("Invalid");

            MyViewComponent <FindDataComponent>
            .InvokedWith(c => c.Invoke(1))
            .ShouldReturn()
            .Content("Invalid");

            MyApplication.StartsFrom <DefaultStartup>();
        }
示例#4
0
 public void IndicatingControllerShouldNotThrowExceptionWithTheAttribute()
 {
     MyViewComponent <AttributesComponent>
     .Instance()
     .ShouldHave()
     .Attributes(attributes => attributes
                 .IndicatingViewComponentExplicitly());
 }
        public void ViewComponentBuilderWithConstructorWithViewComponentShouldNotBeNull()
        {
            var viewComponent        = new NormalComponent();
            var viewComponentBuilder = new MyViewComponent <NormalComponent>(viewComponent);

            Assert.NotNull(viewComponentBuilder);
            Assert.IsAssignableFrom <NormalComponent>(viewComponentBuilder.TestContext.Component);
        }
 public void AttributesShouldNotThrowEceptionWithActionContainingNumberOfAttributes()
 {
     MyViewComponent <AttributesComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldHave()
     .Attributes(withTotalNumberOf: 2);
 }
 public void WithViewEngineOfTypeShouldNotThrowExceptionWithValidViewEngine()
 {
     MyViewComponent <ViewEngineComponent>
     .InvokedWith(c => c.Invoke(new CustomViewEngine()))
     .ShouldReturn()
     .View()
     .WithViewEngineOfType <CustomViewEngine>();
 }
 public void ContainingAttributeOfTypeShouldNotThrowExceptionWithViewComponentWithTheAttribute()
 {
     MyViewComponent <AttributesComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldHave()
     .Attributes(attributes => attributes.ContainingAttributeOfType <CustomAttribute>());
 }
 public void PassingForShouldNotThrowExceptionWithCorrectPredicate()
 {
     MyViewComponent <AttributesComponent>
     .Instance()
     .ShouldHave()
     .Attributes(attributes => attributes
                 .PassingFor <ViewComponentAttribute>(route => route.Name == "Test"));
 }
 public void ShouldReturnResultShouldWorkCorrectlyWithCorrectModel()
 {
     MyViewComponent <StringComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .Result("TestString");
 }
示例#11
0
 public void ShouldReturnNotNullShouldNotThrowExceptionWhenReturnValueNotNull()
 {
     MyViewComponent <NormalComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .NotNull();
 }
示例#12
0
        public void InvokedWithShouldPopulateCorrectActionNameAndActionResultWithAsyncActionCall()
        {
            var testBuilder = MyViewComponent <AsyncComponent>
                              .Instance()
                              .InvokedWith(c => c.InvokeAsync());

            this.CheckViewComponentResultTestBuilder(testBuilder, "InvokeAsync");
        }
示例#13
0
 public void ShouldThrowExceptionShouldCatchAndValidateTypeOfException()
 {
     MyViewComponent <ExceptionComponent>
     .InvokedWith(c => c.Invoke())
     .ShouldThrow()
     .Exception()
     .OfType <IndexOutOfRangeException>();
 }
示例#14
0
        public void InvokedWithShouldPopulateCorrectInvokeNameAndInvocationResultWithNormalActionCall()
        {
            var testBuilder = MyViewComponent <NormalComponent>
                              .Instance()
                              .InvokedWith(c => c.Invoke());

            this.CheckViewComponentResultTestBuilder(testBuilder, "Invoke");
        }
 public void WithRequestShouldNotWorkWithDefaultRequestAction()
 {
     MyViewComponent <HttpRequestComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .Content();
 }
 public void ForumSideBarViewComponentShouldReturnViewWithPicture(bool isWithPicture)
 => MyViewComponent <RandomBlogPostComponent>
 .Instance()
 .WithData(GetBlog())
 .InvokedWith(v => v.Invoke(isWithPicture))
 .ShouldReturn()
 .View(v => v.WithModelOfType <SingleRandomBlogPostModel>(m => m.IsWithPicture
                                                          .ShouldBe(isWithPicture)));
示例#17
0
 public void ShouldReturnContentShouldNotThrowExceptionWithContentResultAndValue()
 {
     MyViewComponent <NormalComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .Content("Test");
 }
 public void WithShouldWorkCorrectly()
 {
     MyViewComponent <ArgumentsComponent>
     .Instance()
     .InvokedWith(c => c.Invoke(With.No <int>(), With.No <RequestModel>()))
     .ShouldReturn()
     .Content("0,");
 }
示例#19
0
 public void ShouldReturnContentWithPredicateShouldNotThrowExceptionWithValidPredicate()
 {
     MyViewComponent <NormalComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .Content(content => content.StartsWith("Te"));
 }
 public void ShouldReturnShouldNotThrowExceptionWithClassTypesAndTypeOf()
 {
     MyViewComponent <NormalComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .ResultOfType(typeof(ContentViewComponentResult));
 }
示例#21
0
 public void ShouldReturnDefaultShouldNotThrowExceptionWhenReturnValueIDefaultForClass()
 {
     MyViewComponent <NullComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .DefaultValue();
 }
 public void ShouldReturnShouldNotThrowExceptionWithInterfaceTypesAndTypeOf()
 {
     MyViewComponent <HtmlContentComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .ResultOfType(typeof(IHtmlContent));
 }
 public void PassingForShouldNotThrowExceptionWithCorrectAssertions()
 {
     MyViewComponent <AttributesComponent>
     .Instance()
     .ShouldHave()
     .Attributes(attributes => attributes
                 .PassingFor <ViewComponentAttribute>(vc => Assert.Equal("Test", vc.Name)));
 }
示例#24
0
 public void ShouldReturnViewShouldNotThrowExceptionWithDefaultView()
 {
     MyViewComponent <ViewResultComponent>
     .Instance()
     .InvokedWith(c => c.Invoke(null))
     .ShouldReturn()
     .View();
 }
 public void NoAttributesShouldNotThrowExceptionWithActionContainingNoAttributes()
 {
     MyViewComponent <NormalComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldHave()
     .NoAttributes();
 }
 public void ShouldReturnViewWithDefaultNameShouldNotThrowExceptionWithCorrectName()
 {
     MyViewComponent <ViewResultComponent>
     .InvokedWith(c => c.Invoke(null))
     .ShouldReturn()
     .View(view => view
           .WithDefaultName());
 }
 public void ShouldReturnShouldThrowExceptionWithClassTypesAndTypeOfAndInterfaceReturn()
 {
     MyViewComponent <HtmlContentComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .ResultOfType(typeof(HtmlContentBuilder));
 }
 public void WithViewEngineShouldNotThrowExceptionWithNullViewEngine()
 {
     MyViewComponent <ViewResultComponent>
     .InvokedWith(c => c.Invoke("Test"))
     .ShouldReturn()
     .View("SomeView")
     .WithViewEngineOfType <CompositeViewEngine>();
 }
示例#29
0
 public void ShouldReturnViewWithNameShouldNotThrowExceptionWithCorrectName()
 {
     MyViewComponent <ViewResultComponent>
     .Instance()
     .InvokedWith(c => c.Invoke("custom"))
     .ShouldReturn()
     .View("Custom");
 }
示例#30
0
 public void ChangingViewComponentNameToShouldNotThrowExceptionWithViewComponentWithTheAttribute()
 {
     MyViewComponent <AttributesComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldHave()
     .Attributes(attributes => attributes.ChangingViewComponentNameTo("Test"));
 }