public void Can_Send_Pagination_View_Model()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            ThingsListViewModel result = (ThingsListViewModel)controller.List(null, 2).Model;

            PagingInfo pagingInfo = result.PagingInfo;

            Assert.AreEqual(pagingInfo.CurrentPage, 2);
            Assert.AreEqual(pagingInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagingInfo.TotalItems, 5);
            Assert.AreEqual(pagingInfo.TotalPages, 2);
        }
        public void Can_Paginate()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            ThingsListViewModel result = (ThingsListViewModel)controller.List(null, 2).Model;

            List <Thing> things = result.Things.ToList();

            Assert.IsTrue(things.Count == 2);
            Assert.AreEqual(things[0].Name, "Thing4");
            Assert.AreEqual(things[1].Name, "Thing5");
        }
        public void Can_Filter_Things()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2", Kind = "Kind2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4", Kind = "Kind3"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5", Kind = "Kind2"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            List <Thing> result = ((ThingsListViewModel)controller.List("Kind2", 1).Model).Things.ToList();

            Assert.AreEqual(result.Count(), 2);
            Assert.IsTrue(result[0].Name == "Thing2" && result[0].Kind == "Kind2");
            Assert.IsTrue(result[1].Name == "Thing5" && result[1].Kind == "Kind2");
        }
Exemple #4
0
    public override void Interact()
    {
        ThingsController tc = GameObject.FindGameObjectWithTag("ThingsController").GetComponent <ThingsController>();

        tc.CurrentMemory = identifier;
        tc.UpdateThePositioning(GameObject.FindGameObjectWithTag("Player").GetComponent <Player>().transform.position);
        StartCoroutine(GameObject.FindGameObjectWithTag("MainCamera").GetComponent <FadeScene>().FadeOutToScene(sceneName));
    }
        public void Generate_Kind_Specific_Thing_Count()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2", Kind = "Kind2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4", Kind = "Kind3"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5", Kind = "Kind2"
                }
            });

            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            int res1   = ((ThingsListViewModel)controller.List("Kind1").Model).PagingInfo.TotalItems;
            int res2   = ((ThingsListViewModel)controller.List("Kind2").Model).PagingInfo.TotalItems;
            int res3   = ((ThingsListViewModel)controller.List("Kind3").Model).PagingInfo.TotalItems;
            int resAll = ((ThingsListViewModel)controller.List(null).Model).PagingInfo.TotalItems;

            Assert.AreEqual(res1, 2);
            Assert.AreEqual(res2, 2);
            Assert.AreEqual(res3, 1);
            Assert.AreEqual(resAll, 5);
        }
Exemple #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext applicationDbContext, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                // Handles exceptions and generates a custom response body
                app.UseExceptionHandler("/api/errors/500");

                // Handles non-success status codes with empty body
                app.UseStatusCodePagesWithReExecute("/api/errors/{0}");

                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();

                var path = env.ContentRootPath;
                loggerFactory.AddFile($"{path}/Logs/Log.txt");
            }

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseSwagger(c =>
            {
                c.PreSerializeFilters.Add((swagger, httpReq) =>
                {
                    swagger.Servers = new List <OpenApiServer>();
                    if (env.IsProduction())
                    {
                        swagger.Servers.Add(new OpenApiServer
                        {
                            Url = $"{httpReq.Scheme}://iot.pedrorendeiro.eu"
                        });
                    }
                    else if (env.IsDevelopment())
                    {
                        swagger.Servers.Add(new OpenApiServer
                        {
                            Url = $"{httpReq.Scheme}://{httpReq.Host.Value}"
                        });
                    }
                });

                c.RouteTemplate = "api/{documentName}/openApi.json";
            });

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.RoutePrefix = "api";
                c.SwaggerEndpoint("v1/openApi.json", "Pedro's IoT API v1");
                c.DocumentTitle = "API Documentation";
                c.EnableFilter();

                c.OAuthClientId(Configuration["AzureAdB2C:ClientId"]);
                c.OAuthClientSecret(Configuration["AzureAdB2C:ClientSecret"]);
                c.OAuthAdditionalQueryStringParams(new Dictionary <string, string>
                {
                    { "prompt", "login" },
                    { "nonce", "defaultNonce" }
                });
                c.OAuthScopeSeparator(" ");
                c.OAuthUsePkce();

                c.DefaultModelRendering(Swashbuckle.AspNetCore.SwaggerUI.ModelRendering.Model);
                c.DefaultModelExpandDepth(1);
                c.DefaultModelsExpandDepth(-1);

                c.DisplayRequestDuration();
                c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.List);
                c.EnableDeepLinking();

                c.EnableValidator();

                c.ConfigObject.AdditionalItems.Add("persistAuthorization", true);

                //c.InjectStylesheet("/static/css/swaggerUI.css");
                //c.InjectJavascript("/custom.js", "text/javascript");
            });

            //applicationDbContext.Database.Migrate();

            ThingsController.UpdateThingsAndPolicies(applicationDbContext);

            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseCors();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseMvcWithDefaultRoute();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapHub <SignalR>("/Hub/SignalR");
                endpoints.MapFallbackToFile("index.html");
            });
        }