Esempio n. 1
0
        //Arrange
        public void StoreSelectionThrowsExceptionOnNull()
        {
            var options = new DbContextOptionsBuilder <SGDB2Context>()
                          .UseInMemoryDatabase(databaseName: "SGDB2")
                          .Options;

            using (var context = new SGDB2Context(options))
            {
                using (var sw = new StringWriter())
                {
                    using (var sr = new StringReader("0\n"))
                    {
                        Customers custy = new Customers
                        {
                            UserName     = "******",
                            Pword        = "yup",
                            DefaultStore = 1
                        };
                        context.Add(custy);
                        context.SaveChanges();

                        //Act
                        bool thrown = false;
                        try
                        {
                            Console.SetOut(sw);
                            Console.SetIn(sr);
                            Customers    customer     = new Customers();
                            StoreMethods storeMethods = new StoreMethods();
                            storeMethods.SetSelectedStore(customer, context);
                        }
                        catch (NullReferenceException)
                        {
                            thrown = true;
                        }
                        //Assert
                        Assert.True(thrown);
                        sw.Close();
                    }
                }
            }
        }//Test 10