コード例 #1
0
        //Arrange
        public void SearchCustomerReturnsCustomerName()
        {
            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("a"))
                    {
                        Customers custy = new Customers {
                            FirstName = "al", LastName = "ali"
                        };
                        context.Add(custy);
                        context.SaveChanges();

                        //Act
                        Console.SetOut(sw);
                        Console.SetIn(sr);
                        Customers    customer     = new Customers();
                        StoreMethods storeMethods = new StoreMethods();
                        storeMethods.SearchForUser(context);


                        //Assert
                        Assert.Contains("al\r\n", sw.ToString());
                    }
                }
            }
        }//Test 9
コード例 #2
0
        //Arrange
        public void LoginProperlyReturnsACustomerType()
        {
            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("abe\nyup"))
                    {
                        context.Add(new Customers
                        {
                            UserName = "******",
                            Pword    = "yup"
                        });

                        context.SaveChanges();

                        //Act
                        Console.SetOut(sw);
                        Console.SetIn(sr);
                        Customers    customer     = new Customers();
                        StoreMethods storeMethods = new StoreMethods();
                        customer = storeMethods.Login(context);


                        //Assert
                        Assert.IsType <Customers>(customer);
                    }
                }
            }
        }//End Test 1
コード例 #3
0
        //Arrange
        public void GetItemTotalReturnsCorrectResult()
        {
            //Act
            var options = new DbContextOptionsBuilder <SGDB2Context>()
                          .UseInMemoryDatabase(databaseName: "SGDB2")
                          .Options;

            using (var context = new SGDB2Context(options))
            {
                Products thing = new Products(50.50m, .50m);
                context.Add(thing);
                StoreMethods storeMethod = new StoreMethods();
                var          result      = storeMethod.GetItemTotal(4, thing, context);

                //Assert
                Assert.Equal(101.00m, result);
            }
        }//Test 8
コード例 #4
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