Esempio n. 1
0
        public void Initialize()
        {
            UserInterface userInterface = new UserInterface();

            MyApplication myApplication = new MyApplication(userInterface);
            TheData theData = new TheData(userInterface, myApplication);

            MainWindow mainForm = new MainWindow
            {
                ViewModel = new MainViewModel(myApplication, theData)
            };

            userInterface.MainWindow = mainForm;
            userInterface.Run();
        }
Esempio n. 2
0
        public MainViewModel(MyApplication myApplication, TheData theData)
        {
            if (myApplication == null) throw new ArgumentNullException("myApplication");
            if (theData == null) throw new ArgumentNullException("theData");

            this.myApplication = myApplication;

            TheDataModel = new TheDataViewModel(theData);
            ExitButtonModel = new ExitButtonModel(myApplication);
            SaveButtonModel = new SaveButtonModel(theData);
            ChangeButtonModel = new ChangeButtonModel(theData);

            myApplication.BeforeExiting += HandleMyApplicationBeforeExiting;
            myApplication.ExitCanceled += HandleMyApplicationExitCanceled;
        }
        public void ViewComponentDescriptorCacheShouldWorkCorrectlyAndReturnDescriptor()
        {
            MyApplication.StartsFrom <DefaultStartup>();

            MyViewComponent <NormalComponent>
            .InvokedWith(c => c.Invoke())
            .ShouldPassForThe <NormalComponent>(vc =>
            {
                var cache = vc.HttpContext.RequestServices.GetService <IViewComponentDescriptorCache>();
                var viewComponentDescriptor = cache.GetViewComponentDescriptor(vc.GetType().GetMethod("Invoke"));

                Assert.True(viewComponentDescriptor.GetType() == typeof(ViewComponentDescriptor));
            });

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 4
0
        public void ExplicitMockTempDataProviderShouldOverrideIt()
        {
            MyApplication
            .StartsFrom <DataStartup>()
            .WithServices(services =>
            {
                services.ReplaceTempDataProvider();
            });

            var tempDataProvider = TestServiceProvider.GetService <ITempDataProvider>();

            Assert.NotNull(tempDataProvider);
            Assert.IsAssignableFrom <TempDataProviderMock>(tempDataProvider);

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 5
0
        public void WithResolvedDependencyForShouldChooseCorrectConstructorWithLessDependenciesForPocoController()
        {
            MyController <FullPocoController>
            .Instance()
            .WithDependencies(dependencies => dependencies
                              .With <IInjectedService>(new InjectedService()))
            .ShouldPassForThe <FullPocoController>(controller =>
            {
                Assert.NotNull(controller);
                Assert.NotNull(controller.InjectedService);
                Assert.Null(controller.AnotherInjectedService);
                Assert.Null(controller.InjectedRequestModel);
            });

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void ToDataTokenShouldThrowExceptionWithIncorrectDataTokenKey()
        {
            MyApplication.StartsFrom <RoutingStartup>();

            Test.AssertException <RouteAssertionException>(
                () =>
            {
                MyRouting
                .Configuration()
                .ShouldMap("/Test")
                .ToDataToken("name");
            },
                "Expected route '/Test' to contain data token with 'name' key but such was not found.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void IsUsingWithStartUpClassShouldThrowExceptionWithServiceProviderWhenTestServicesAreMissing()
        {
            Test.AssertException <InvalidOperationException>(
                () =>
            {
                MyApplication
                .StartsFrom <InvalidStartup>()
                .WithConfiguration(configuration => configuration
                                   .Add("General:Environment", "Invalid"));

                TestServiceProvider.GetService <IInjectedService>();
            },
                "Testing services could not be resolved. If your ConfigureServices method returns an IServiceProvider, you should either change it to return 'void' or manually register the required testing services by calling one of the provided IServiceCollection extension methods in the 'MyTested.AspNetCore.Mvc' namespace.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void ExplicitMockSessionShouldOverrideIt()
        {
            MyApplication
            .StartsFrom <SessionDataStartup>()
            .WithServices(services =>
            {
                services.ReplaceSession();
            });

            var session = TestServiceProvider.GetService <ISessionStore>();

            Assert.NotNull(session);
            Assert.IsAssignableFrom <SessionStoreMock>(session);

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void ExplicitMockDistributedCacheShouldOverrideIt()
        {
            MyApplication
            .StartsFrom <DataStartup>()
            .WithServices(services =>
            {
                services.ReplaceDistributedCache();
            });

            var distributedCache = TestServiceProvider.GetService <IDistributedCache>();

            Assert.NotNull(distributedCache);
            Assert.IsAssignableFrom <DistributedCacheMock>(distributedCache);

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 10
0
        public void IsUsingWithAdditionalServicesShouldUseThem()
        {
            MyApplication
            .StartsFrom <CustomStartup>()
            .WithServices(services =>
            {
                services.AddTransient <IInjectedService, InjectedService>();
            });

            var injectedServices = TestServiceProvider.GetService <IInjectedService>();

            Assert.NotNull(injectedServices);
            Assert.IsAssignableFrom(typeof(InjectedService), injectedServices);

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void ToDataTokensShouldThrowExceptionWithIncorrectDataTokensWithMultipleCountError()
        {
            MyApplication.StartsFrom <RoutingStartup>();

            Test.AssertException <RouteAssertionException>(
                () =>
            {
                MyRouting
                .Configuration()
                .ShouldMap("/Test")
                .ToDataTokens(new { id = 1, query = "invalid", another = "another", fourth = "test" });
            },
                "Expected route '/Test' to contain 4 data tokens but in fact found 2.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void ToDataTokenShouldThrowExceptionWithIncorrectDataTokensWithSingleCountError()
        {
            MyApplication.StartsFrom <RoutingStartup>();

            Test.AssertException <RouteAssertionException>(
                () =>
            {
                MyRouting
                .Configuration()
                .ShouldMap("/Test")
                .ToDataTokens(new { id = 1 });
            },
                "Expected route '/Test' to contain 1 data token but in fact found 2.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void ToDataTokensShouldThrowExceptionWithIncorrectDataTokens()
        {
            MyApplication.StartsFrom <RoutingStartup>();

            Test.AssertException <RouteAssertionException>(
                () =>
            {
                MyRouting
                .Configuration()
                .ShouldMap("/Test")
                .ToDataTokens(new { random = "value", another = "invalid" });
            },
                "Expected route '/Test' to contain data token with 'another' key and the provided value but the value was different.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 14
0
        public void DefaultConfigAndAdditionalRoutesShouldSetOnlyThem()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithRoutes(routes =>
            {
                routes.MapRoute(
                    name: "another",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            var setRoutes = TestApplication.Router as RouteCollection;

            Assert.NotNull(setRoutes);
            Assert.Equal(3, setRoutes.Count);
        }
        public void WithInvalidTempDataValueShouldReturnBadRequestForPocoController()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services => services
                          .TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>());

            MyController <FullPocoController>
            .Instance()
            .WithTempData(tempData => tempData.WithEntry("invalid", "value"))
            .Calling(c => c.TempDataAction())
            .ShouldReturn()
            .BadRequest();

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 16
0
        private bool ProcessImport()

        {
            var num1 = 0;
            var num2 = 0;

            BusyMsg("Applying...");
            Enabled = false;
            var num3 = 0;
            var num4 = lstImport.Items.Count - 1;

            for (var index = 0; index <= num4; ++index)
            {
                if (!lstImport.Items[index].Checked)
                {
                    continue;
                }
                if (!_importBuffer[Convert.ToInt32(lstImport.Items[index].Tag)].Apply())
                {
                    ++num3;
                }
                ++num1;
                ++num2;
                if (num2 < 9)
                {
                    continue;
                }
                BusyMsg("Applying: " + Convert.ToString(index) + " records done.");
                Application.DoEvents();
                num2 = 0;
            }

            Enabled = true;
            BusyMsg("Saving...");
            DatabaseAPI.Database.PowerEffectVersion.SourceFile   = dlgBrowse.FileName;
            DatabaseAPI.Database.PowerEffectVersion.RevisionDate = DateTime.Now;
            DatabaseAPI.Database.PowerEffectVersion.Revision     = Convert.ToInt32(udRevision.Value);
            DatabaseAPI.MatchAllIDs();
            var serializer = MyApplication.GetSerializer();

            DatabaseAPI.SaveMainDatabase(serializer);
            BusyHide();
            MessageBox.Show($"Import of {num1} records completed!\r\nOf these, {num3} records were found read-only.",
                            "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
            DisplayInfo();
            return(false);
        }
        public void WithSetShouldSetupDbContext()
        {
            MyApplication
            .StartsFrom <TestStartup>()
            .WithServices(services =>
            {
                services.AddDbContext <CustomDbContext>(options =>
                                                        options.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=TestDb;Trusted_Connection=True;MultipleActiveResultSets=true;Connect Timeout=30;"));
            });

            MyController <DbContextController>
            .Instance()
            .WithData(data => data
                      .WithSet <CustomDbContext, CustomModel>(set => set
                                                              .Add(new CustomModel
            {
                Id   = 1,
                Name = "Test"
            })))
            .Calling(c => c.Find(1))
            .ShouldReturn()
            .Ok(ok => ok
                .WithModelOfType <CustomModel>()
                .Passing(m => m.Name == "Test"));

            MyController <DbContextController>
            .Instance()
            .WithData(data => data
                      .WithSet <CustomDbContext, CustomModel>(set => set
                                                              .Add(new CustomModel
            {
                Id   = 2,
                Name = "Test"
            })))
            .Calling(c => c.Find(1))
            .ShouldReturn()
            .NotFound();

            MyController <DbContextController>
            .Instance()
            .Calling(c => c.Find(1))
            .ShouldReturn()
            .NotFound();

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 18
0
        public void MemoryCacheWithNoNumberShouldNotThrowExceptionWithViewComponentAnyCacheEntries()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services => services.AddMemoryCache());

            MyViewComponent <MemoryCacheValuesComponent>
            .Instance()
            .InvokedWith(c => c.Invoke())
            .ShouldHave()
            .MemoryCache()
            .AndAlso()
            .ShouldReturn()
            .View();

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 19
0
        public void NoMemoryCacheShouldNotThrowExceptionWithViewComponentNoCacheEntries()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services => services.AddMemoryCache());

            MyViewComponent <NormalComponent>
            .Instance()
            .InvokedWith(c => c.Invoke())
            .ShouldHave()
            .NoMemoryCache()
            .AndAlso()
            .ShouldReturn()
            .Content();

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 20
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.member_list, container, false);

            _activity      = (MainActivity)Activity;
            _myApplication = _activity.ApplicationContext as MyApplication;

            _membersListView            = view.FindViewById <ListView>(Resource.Id.memberListView);
            _membersListView.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs args)
            {
                OnItemClick(args);
            };

            getData();

            return(view);
        }
        public void ConfigureContainerServicesShouldBeRegisteredFromStaticStartup()
        {
            MyApplication.StartsFrom <StaticStartup>();

            var injectedService = TestApplication.Services.GetService <IInjectedService>();
            var injectedServiceFromRouteServiceProvider = TestApplication.RoutingServices.GetService <IInjectedService>();

            Assert.NotNull(injectedService);
            Assert.IsAssignableFrom <InjectedService>(injectedService);

            Assert.NotNull(injectedServiceFromRouteServiceProvider);
            Assert.IsAssignableFrom <InjectedService>(injectedServiceFromRouteServiceProvider);

            MyApplication
            .IsRunningOn(server => server
                         .WithStartup <DefaultStartup>());
        }
        public void MissingRoutingServicesShouldThrowException()
        {
            Test.AssertException <InvalidOperationException>(
                () =>
            {
                MyApplication
                .StartsFrom <DefaultStartup>()
                .WithServices(services => services.Remove <IRoutingServices>());

                TestServiceProvider.GetService <IInjectedService>();
            },
                "No service for type 'MyTested.AspNetCore.Mvc.Internal.Contracts.IRoutingServices' has been registered.");

            MyApplication
            .IsRunningOn(server => server
                         .WithStartup <DefaultStartup>());
        }
        public void ControllerWithNoParameterlessConstructorAndNoServicesShouldThrowProperException()
        {
            MyApplication.StartsFrom <DefaultStartup>();

            Test.AssertException <UnresolvedServicesException>(
                () =>
            {
                MyController <NoParameterlessConstructorController>
                .Instance()
                .Calling(c => c.OkAction())
                .ShouldReturn()
                .Ok();
            },
                "NoParameterlessConstructorController could not be instantiated because it contains no constructor taking no parameters.");

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 24
0
        static void Main(string[] args)
        {
            MyApplication obj = new MyApplication();

            obj.Menu();
            Console.WriteLine("Клонирование");
            Complex objst = new Complex {
                r = 5, i = 9
            };
            Complex objst1 = (Complex)objst.Clone();

            objst1.i = 4;
            Console.WriteLine($"Клон объекта 1 {objst1.ToString()}");
            Console.WriteLine($"Объект 1 {objst.ToString()}");
            Console.WriteLine("\nДля выхода из программы нажмите [Enter]");
            Console.ReadLine();
        }
Esempio n. 25
0
        public void WithSetShouldSetupDbContext()
        {
            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()
            .WithDbContext(dbContext => dbContext
                           .WithSet <CustomDbContext, CustomModel>(set => set
                                                                   .Add(new CustomModel
            {
                Id   = 1,
                Name = "Test"
            })))
            .InvokedWith(c => c.Invoke(1))
            .ShouldReturn()
            .View()
            .WithModelOfType <CustomModel>()
            .Passing(m => m.Name == "Test");

            MyViewComponent <FindDataComponent>
            .Instance()
            .WithDbContext(dbContext => dbContext
                           .WithSet <CustomDbContext, CustomModel>(set => set
                                                                   .Add(new CustomModel
            {
                Id   = 2,
                Name = "Test"
            })))
            .InvokedWith(c => c.Invoke(1))
            .ShouldReturn()
            .Content("Invalid");

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

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 26
0
        public void CallingShouldWorkCorrectlyWithFromServices()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services =>
            {
                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            });

            MyController <MvcController>
            .Instance()
            .Calling(c => c.WithService(From.Services <IHttpContextAccessor>()))
            .ShouldReturn()
            .Ok();

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void WithRequestShouldNotWorkWithDefaultRequestActionForPocoController()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services =>
            {
                services.AddHttpContextAccessor();
            });

            MyController <FullPocoController>
            .Instance()
            .Calling(c => c.WithRequest())
            .ShouldReturn()
            .BadRequest();

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void WhichShouldNotResolveControllerContextWhenWithMethodsAreCalledInInnerBuilder()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services => services
                          .AddTransient <IInjectedService, InjectedService>());

            const string contextTestKey   = "ControllerContext";
            const string contextTestValue = "Context Value";

            MyPipeline
            .Configuration()
            .ShouldMap("/Pipeline/Action?controller=true")
            .To <PipelineController>(c => c.Action())
            .Which(controller => controller
                   .WithHttpContext(context => context.Features.Set(new AnotherInjectedService()))
                   .WithHttpRequest(request => request.WithHeader(contextTestKey, contextTestValue))
                   .WithUser(user => user.WithUsername(contextTestKey))
                   .WithRouteData(new { Id = contextTestKey })
                   .WithControllerContext(context => context.RouteData.Values.Add(contextTestKey, contextTestValue))
                   .WithActionContext(context => context.ModelState.AddModelError(contextTestKey, contextTestValue))
                   .WithTempData(tempData => tempData.WithEntry(contextTestKey, contextTestValue))
                   .WithSetup(controller => controller.HttpContext.Features.Set(new InjectedService())))
            .ShouldReturn()
            .Ok()
            .AndAlso()
            .ShouldPassForThe <PipelineController>(controller =>
            {
                const string testValue = "ControllerFilter";
                Assert.Equal(testValue, controller.Data);
                Assert.True(controller.RouteData.Values.ContainsKey(testValue));
                Assert.True(controller.RouteData.Values.ContainsKey(contextTestKey));
                Assert.True(controller.RouteData.Values.ContainsKey("Id"));
                Assert.True(controller.ControllerContext.ActionDescriptor.Properties.ContainsKey(testValue));
                Assert.True(controller.ModelState.ContainsKey(testValue));
                Assert.True(controller.ModelState.ContainsKey(contextTestKey));
                Assert.NotNull(controller.HttpContext.Features.Get <PipelineController>());
                Assert.NotNull(controller.HttpContext.Features.Get <InjectedService>());
                Assert.NotNull(controller.HttpContext.Features.Get <AnotherInjectedService>());
                Assert.True(controller.HttpContext.Request.Headers.ContainsKey(contextTestKey));
                Assert.True(controller.TempData.ContainsKey(contextTestKey));
                Assert.True(controller.User.Identity.Name == contextTestKey);
            });

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void CallingShouldPopulateCorrectActionNameAndActionResultWithNormalActionCallForPocoController()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services =>
            {
                services.AddHttpContextAccessor();
            });

            var actionResultTestBuilder = MyController <FullPocoController>
                                          .Instance()
                                          .Calling(c => c.OkResultAction());

            this.CheckActionResultTestBuilder(actionResultTestBuilder, "OkResultAction");

            MyApplication.StartsFrom <DefaultStartup>();
        }
        public void CallingShouldPopulateCorrectActionNameWithTaskActionCallForPocoController()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services =>
            {
                services.AddHttpContextAccessor();
            });

            var voidActionResultTestBuilder = MyController <FullPocoController>
                                              .Instance()
                                              .Calling(c => c.EmptyActionAsync());

            this.CheckActionName(voidActionResultTestBuilder, "EmptyActionAsync");

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 31
0
        public void MemoryCacheWithNumberShouldNotThrowExceptionWithCorrectCacheEntries()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services => services.AddMemoryCache());

            MyController <MvcController>
            .Instance()
            .Calling(c => c.AddMemoryCacheAction())
            .ShouldHave()
            .MemoryCache(withNumberOfEntries: 2)
            .AndAlso()
            .ShouldReturn()
            .Ok();

            MyApplication.StartsFrom <DefaultStartup>();
        }
Esempio n. 32
0
        public void NoMemoryCacheShouldNotThrowExceptionWithNoCacheEntries()
        {
            MyApplication
            .StartsFrom <DefaultStartup>()
            .WithServices(services => services.AddMemoryCache());

            MyController <MvcController>
            .Instance()
            .Calling(c => c.Ok())
            .ShouldHave()
            .NoMemoryCache()
            .AndAlso()
            .ShouldReturn()
            .Ok();

            MyApplication.StartsFrom <DefaultStartup>();
        }
		public void SetUp()
		{
			var testInstance = new MyApplication();
			oldApplicationInstanceGetter = AspViewEngine.GetApplicationInstance;
			AspViewEngine.GetApplicationInstance = () => testInstance;
			var basePath = Environment.CurrentDirectory;
			engine = new AspViewEngine();
			engineWithTestAccess = engine;			

			engineWithTestAccess.SetViewSourceLoader(new StubViewSourceLoader());
			engineWithTestAccess.SetCompilationContext(
				new List<ICompilationContext>
					{
						new CompilationContext(
							new DirectoryInfo(basePath),
							new DirectoryInfo(basePath),
							new DirectoryInfo(basePath),
							new DirectoryInfo(basePath))
					});
		}
			static void Main(string[] args)
			{
				MyApp = new MyApplication();
				MyApp.Run(args);
			}
Esempio n. 35
0
 public bool Load(MyApplication application)
 {
     throw new NotImplementedException();
 }
Esempio n. 36
0
        public ExitButtonModel(MyApplication myApplication)
        {
            if (myApplication == null) throw new ArgumentNullException("myApplication");

            this.myApplication = myApplication;
        }
			static void Main(string[] args)
			{
				System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
				MyApp = new MyApplication();
				MyApp.Run(args);
			}
Esempio n. 38
0
        public ExitCommand(MyApplication myApplication)
        {
            if (myApplication == null) throw new ArgumentNullException("myApplication");

            this.myApplication = myApplication;
        }
Esempio n. 39
0
			static void Main()
			{
                MyApplication a = new MyApplication();
				a.Run(new string[] {});
			}
 public bool Load(MyApplication application)
 {
     return true;
 }