コード例 #1
0
 public async Task CreatePerson()
 {
     while (true)
     {
         var flag = true;
         using (var context = new SomeContext())
         {
             Console.WriteLine("Do you want to add a person in table?(type \"y\" ifyes, \"other key\" if not)");
             string answer = Console.ReadLine();
             if (answer != "y")
             {
                 break;
             }
             while (flag)
             {
                 var person = new Person();
                 Console.WriteLine("\nEnter name:");
                 person.Name = Console.ReadLine();
                 if (context.Persons.All(x => x.Name != person.Name))
                 {
                     flag = false;
                     context.Add(person);
                     context.SaveChanges();
                 }
                 else
                 {
                     Console.WriteLine($"This person is already in table, choose another name!");
                 }
             }
         }
     }
 }
コード例 #2
0
        [Fact] // CodePlex 2029
        public void InitializeDatabase_does_not_create_new_connections()
        {
            using (var context = new SomeContext())
            {
                context.Database.Initialize(force: false);

                using (var transactionContext = new SomeTransactionContext(context.Database.Connection))
                {
                    var initializer = new TransactionContextInitializer <TransactionContext>();

                    var recorder = new ConnectionRecorder();
                    DbInterception.Add(recorder);
                    try
                    {
                        using (transactionContext.Database.BeginTransaction())
                        {
                            initializer.InitializeDatabase(transactionContext);
                        }

                        Assert.Equal(1, recorder.Connections.Count);
                    }
                    finally
                    {
                        DbInterception.Remove(recorder);
                    }
                }
            }
        }
コード例 #3
0
        [Fact] // CodePlex 2029
        public void InitializeDatabase_does_not_create_new_connections()
        {
            using (var context = new SomeContext())
            {
                context.Database.Initialize(force: false);

                using (var transactionContext = new SomeTransactionContext(context.Database.Connection))
                {
                    var initializer = new TransactionContextInitializer<TransactionContext>();

                    var recorder = new ConnectionRecorder();
                    DbInterception.Add(recorder);
                    try
                    {
                        using (transactionContext.Database.BeginTransaction())
                        {
                            initializer.InitializeDatabase(transactionContext);
                        }

                        Assert.Equal(1, recorder.Connections.Count);
                    }
                    finally
                    {
                        DbInterception.Remove(recorder);
                    }
                }
            }
        }
コード例 #4
0
 public async Task Choose()
 {
     using (var context = new SomeContext())
     {
         var   row = context.Persons.OrderBy(x => Guid.NewGuid()).ToList();
         Mixed mix = new Mixed();
         mix.Mixing();
         Person temp = null;
         foreach (var person in row)
         {
             if (temp != null)
             {
                 temp.GiftedFriend = person.Name;
             }
             else
             {
                 row.Last().GiftedFriend = person.Name;
             }
             temp = person;
         }
         Console.WriteLine($"\nThe list of people who gives gifts to whom (to check that no one is offended):\n");
         foreach (var item in context.Persons)
         {
             Console.WriteLine($"{item.Name} gifts to {item.GiftedFriend}");
         }
         context.SaveChanges();
     }
 }
コード例 #5
0
    public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
    {
        // just sample check
        if (node.Url.StartsWith("/Administration/"))
        {
            return(context.User.Identity.Name == "admin");
        }
        // or you can query your db
        using (var dbContext = new SomeContext())
        {
            var userName    = context.User.Identity.Name;
            var currentUser = dbContext.Users.First(u => u.AccountName == userName);
            if (node.Url.StartsWith("/Administration/") && currentUser.Permission.IsAllowdAdminsPage)
            {
                return(true);
            }
            // others checks
        }
        // or you can access your current page and get data from it
        var currentPage = context.Handler as Page;

        if (currentPage != null)
        {
            var someControl = currentPage.FindControl("someControl");
            // some custom checks
        }
        return(base.IsAccessibleToUser(context, node));
    }
コード例 #6
0
    public MainWindow()
    {
        InitializeComponent();
        var context = new SomeContext();

        DataContext = context;
        context.AddPerson();
    }
コード例 #7
0
 //[Test, TestCaseSource(typeof(MyFactoryClass), "TestCases")]
 public override int[] ExecuteParams(DataTablesParam dataTablesParam)
 {
     DataContext.Dispose(); //reset datacontext in order to clear local
     DataContext = new SomeContext();
     int[] returnVar = base.ExecuteParams(dataTablesParam);
     Assert.AreEqual(returnVar.Length, DataContext.Models.Local.Count, "records loaded in memory");
     return(returnVar);
 }
コード例 #8
0
 public override int[] ExecuteParams(DataTablesParam dataTablesParam)
 {
     DataContext.Dispose(); //reset datacontext in order to clear local 
     DataContext = new SomeContext();
     int[] returnVar = base.ExecuteParams(dataTablesParam);
     Assert.AreEqual(returnVar.Length, DataContext.Models.Local.Count, "records loaded in memory");
     return returnVar;
 }
コード例 #9
0
    public void Execute(SomeContext context)
    {
        var data = context.GetStorage <TType>().Cast <IEntityWithSomeFunction>();

        foreach (var item in data)
        {
            item.SomeFunction();
        }
    }
コード例 #10
0
        private static SomeContext CreateDb()
        {
            var context = new SomeContext();
            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "",
                string.Format("Data Source=\"{0}\";Password={1}", DbFile, Password));

            context.Database.Initialize(true);
            return context;
        }
コード例 #11
0
        public void store_and_retrieve()
        {
            var context = new TestContext();
            var data    = new SomeContext();

            context.Store(data);

            context.Retrieve <SomeContext>().ShouldBeTheSameAs(data);
        }
コード例 #12
0
 public SomeContextScope(object stateData1, object stateData2)
 {
     if (SomeContext.Current == null)
     {
         SomeContext context = new SomeContext(stateData1, stateData2);
         SomeContext.Current = context;
         m_contextCreated = true;
     }
 }
コード例 #13
0
    public T DoIt(SomeContext someContext, string name)
    {
        string contextVal = someContext.GetValue(name);

        var thing = new T {
            MyProperty = contextVal
        };

        return(thing);
    }
コード例 #14
0
 public void ShowMan()
 {
     using (var context = new SomeContext())
     {
         Console.WriteLine($"Enter your name to find out who you are buying the gift for:\n");
         var yourName  = Console.ReadLine();
         var recipient = context.Persons.Single(x => x.Name == yourName).GiftedFriend;
         Console.WriteLine($"{yourName} you're {recipient}'s SS agent, congratulations!!!\n");
     }
 }
コード例 #15
0
        public void SimpleInterfaceRoutingWithContextShouldWork()
        {
            var processor    = Substitute.For <IMessageHandler <SomeContext, SomeDto> >();
            var router       = RoutingTestEnvironment.GetInterfaceBasedRoutingProvider(processor);
            var routedObject = RoutingTestEnvironment.GetTestDtoData();
            var context      = new SomeContext();

            router.RouteObject(context, routedObject);
            processor.Received().HandleMessage(context, routedObject);
        }
コード例 #16
0
        public void ShowFallPass()
        {
            int count = 0;

            while (count <= Password.Length)
            {
                Console.Write(SomeContext.HidePass(Password.Length));
                count++;
            }
        }
コード例 #17
0
        internal string GetDogName(SomeContext <ComplexData> context)
        {
            var name = _dog.Name;

            context.Collection.Add(new ComplexData()
            {
                Name = name
            });
            return(name);
        }
コード例 #18
0
        public void Dto_with_no_properties_causes_null_exception()
        {
            using (var context = new SomeContext(InMemoryOptions.Create <SomeContext>()))
            {
                //ATTEMPT
                var ex = Assert.Throws <InvalidOperationException>(() => context.SetupSingleDtoAndEntities <ImutableDto>());

                //VERIFY
                ex.Message.ShouldEqual("The ImutableDto class inherits ILinkToEntity<T> but has no properties in it!");
            }
        }
コード例 #19
0
 public void ShowTableOfPersons()
 {
     using (var context = new SomeContext())
     {
         Console.WriteLine($"This is table of persons:");
         foreach (var personInTable in context.Persons)
         {
             Console.WriteLine($"{personInTable.Id} --- {personInTable.Name}");
         }
     }
 }
コード例 #20
0
        public void Dto_with_no_properties_causes_null_exception()
        {
            using (var context = new SomeContext(InMemoryOptions.Create <SomeContext>()))
            {
                //ATTEMPT
                var ex = Assert.Throws <InvalidOperationException>(() => context.SetupSingleDtoAndEntities <ImutableDto>());

                //VERIFY
                ex.Message.ShouldEqual("A DTO using the ILinkToEntity<T> must contain at least one Property!");
            }
        }
コード例 #21
0
        public EntityFramework()
        {
            var oldQueryable = SomeModelQueryable;

            DataContext = new SomeContext();
            DataContext.Database.Initialize(true);
            foreach (var sm in oldQueryable)
            {
                DataContext.Models.Add(sm);
            }
            DataContext.SaveChanges();
        }
コード例 #22
0
 static async Task Main(string[] args)
 {
     using (var context = new SomeContext())
     {
         await context
         .Customers
         .Where(c => c.Email.Contains("42"))
         .CustomUpdateAsync((c) => new Customer()
         {
             Email = "4242"
         });
     }
 }
コード例 #23
0
 public EntityFramework(IDbConnectionFactory connectionFactory)
 {
     _defaultConnectionFactory = Database.DefaultConnectionFactory;
     Database.DefaultConnectionFactory = connectionFactory;
     var oldQueryable = SomeModelQueryable;
     DataContext = new SomeContext();
     DataContext.Database.Initialize(true);
     foreach (var sm in oldQueryable)
     {
         DataContext.Models.Add(sm);
     }
     DataContext.SaveChanges();
 }
コード例 #24
0
        public void InitTest()
        {
            DataContext = new SomeContext();
            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "", string.Format("Data Source=\"{0}\";Password={1}", DbFile, Password));

            DataContext.Database.Initialize(true);
            for (var i = 0; i < 100; i++)
            {
                DataContext.Models.Add(new SomeModel() {DisplayName = "Name " + i});

            }
            DataContext.SaveChanges();
        }
コード例 #25
0
 public void DeleteAll()
 {
     using (var context = new SomeContext())
     {
         Console.WriteLine($"Do you wanna delete whole table? (type \"y\" if yes, \"other key\" if not)");
         var answer = Console.ReadLine();
         if (answer == "y")
         {
             var table = context.Persons.Where(x => x.Name != null);
             context.Persons.RemoveRange(table);
             context.SaveChanges();
         }
     }
 }
コード例 #26
0
        public EntityFramework(IDbConnectionFactory connectionFactory)
        {
            _defaultConnectionFactory         = Database.DefaultConnectionFactory;
            Database.DefaultConnectionFactory = connectionFactory;
            var oldQueryable = SomeModelQueryable;

            DataContext = new SomeContext();
            DataContext.Database.Initialize(true);
            foreach (var sm in oldQueryable)
            {
                DataContext.Models.Add(sm);
            }
            DataContext.SaveChanges();
        }
コード例 #27
0
        public EntityFramework(SomeContext dataContext)
        {
            DataContext = dataContext;
            if (DataContext.Models.Any())
            {
                DataContext.Database.ExecuteSqlCommand("DELETE FROM SomeModels");
            }
            foreach (var sm in SomeModelQueryable)
            {
                DataContext.Models.Add(sm);
            }
            DataContext.SaveChanges();

            SomeModelQueryable = DataContext.Models;
        }
コード例 #28
0
        static void Main(string[] args)
        {
            _connection = $"Host={args[0]};Port={args[1]};Username={args[2]};Password={args[3]};Database=some_context;";

            using (var ctx = new SomeContext())
            {
                ctx.Database.EnsureCreated();

                var _ =
                    ctx.SomeDateTimes
                    .Where(s => s.Updated > DateTime.Now.AddDays(-1))
                    .ToArray();

                ctx.Database.EnsureDeleted();
            }

            Console.WriteLine("Finished!");
        }
コード例 #29
0
 public void DeletePerson()
 {
     using (var context = new SomeContext())
     {
         Console.WriteLine($"Do you wanna delete someone from table? (type \"y\" ifyes, \"other key\" if not)");
         var answer = Console.ReadLine();
         if (answer == "y")
         {
             ShowTable showTable = new ShowTable();
             showTable.ShowTableOfPersons();
             Console.WriteLine($"Choose who will be deleted from table. (choose number)");
             var id     = int.Parse(Console.ReadLine());
             var person = new Person {
                 Id = id
             };
             context.Persons.Remove(person);
             context.SaveChanges();
         }
     }
 }
コード例 #30
0
 // If you have already instantiated a context to use, then you can pass it in here
 public RoleManager <IdentityRole> Create(SomeContext context)
 {
     return(new RoleManager <IdentityRole>(new RoleStore <IdentityRole, string>(context)));
 }
コード例 #31
0
 public HomeController(SomeContext context)
 {
     _context = context;
 }
コード例 #32
0
 private void RetHifhtPas(string Password)
 {
     Pass = SomeContext.HidePass(Password.Length);
 }
コード例 #33
0
        public void store_and_retrieve()
        {
            var context = new TestContext();
            var data = new SomeContext();

            context.Store(data);

            context.Retrieve<SomeContext>().ShouldBeTheSameAs(data);
        }
コード例 #34
0
 public static string ReturnBadTime()
 {
     return(SomeContext.GetDate(saveDayBad, saveHourBad, saveMinutesBad, saveSecBad));
 }
コード例 #35
0
 public SomeRescueContextImpl(SomeContext context, Exception exception)
     : base(context)
 {
     Exception = exception;
 }
コード例 #36
0
 public static string ReturnGoodTime()
 {
     return(SomeContext.GetDate(saveDayGood, saveHourGood, saveMinutesGood, saveSecGood));
 }
コード例 #37
0
 public DashboardController(SomeContext context)
 {
     _context = context;
 }