Пример #1
0
        public void AddSupportTo <T>(IEnumerable <T> initialData = null) where T : class
        {
            MockData.Add(typeof(T), new DataMocker <T>(initialData));

            MockContext.Setup(c => c.Query <T>()).Returns(((IDataMocker <T>)MockData[typeof(T)]).GetAll());

            MockContext.Setup(c => c.Add(It.IsAny <T>())).Callback <T>(x => ((IDataMocker <T>)MockData[typeof(T)]).Add(x));
            MockContext.Setup(c => c.AddRange(It.IsAny <IEnumerable <T> >())).Callback <IEnumerable <T> >(x => ((IDataMocker <T>)MockData[typeof(T)]).AddRange(x));

            MockContext.Setup(c => c.Remove(It.IsAny <T>())).Callback <T>(x => ((IDataMocker <T>)MockData[typeof(T)]).Remove(x));
            MockContext.Setup(c => c.RemoveRange(It.IsAny <IEnumerable <T> >())).Callback <IEnumerable <T> >(x => ((IDataMocker <T>)MockData[typeof(T)]).RemoveRange(x));

            MockContext.Setup(c => c.SaveChanges()).Callback(() =>
            {
                foreach (var mockData in MockData)
                {
                    mockData.Value.SaveChanges();
                }
            });
        }
Пример #2
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BlueModasDbContext applicationDbContext)
        {
            app.UseCors(x => x
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .SetIsOriginAllowed(origin => true)
                        .AllowCredentials());

            MockData.Add(applicationDbContext);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSwagger(c =>
            {
                c.SerializeAsV2 = true;
            });


            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Blue Modas API");
                c.RoutePrefix = string.Empty;
                c.EnableFilter();
            });

            app.UseHttpsRedirection();

            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }