コード例 #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>();
        }
コード例 #3
0
        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());
 }
コード例 #5
0
        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);
 }
コード例 #7
0
 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");
        }
コード例 #15
0
 public void WithRequestShouldNotWorkWithDefaultRequestAction()
 {
     MyViewComponent <HttpRequestComponent>
     .Instance()
     .InvokedWith(c => c.Invoke())
     .ShouldReturn()
     .Content();
 }
コード例 #16
0
 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();
 }
コード例 #26
0
 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));
 }
コード例 #28
0
 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"));
 }