コード例 #1
0
        public Task <int> PostLocationCountry(LocationCountry locationCountry)
        {
            int result = 0;

            using (IDbConnection db = GetConnection())
            {
                db.Open();

                if (locationCountry.LocationName != "")
                {
                    var p = new DynamicParameters();

                    p.Add("@LocationId", locationCountry.LocationId, DbType.Int32, ParameterDirection.Input);
                    p.Add("@LocationName", locationCountry.LocationName, DbType.String, ParameterDirection.Input);
                    p.Add("@LocationCreatedDate", locationCountry.LocationCreatedDate, DbType.String, ParameterDirection.Input);
                    p.Add("@LocationCreatedBy", locationCountry.LocationCreatedBy, DbType.Int32, ParameterDirection.Input);
                    p.Add("@LocationModifiedDate", locationCountry.LocationModifiedDate, DbType.DateTime, ParameterDirection.Input);
                    p.Add("@LocationModifiedBy", locationCountry.LocationModifiedBy, DbType.Int32, ParameterDirection.Input);
                    p.Add("@LocationStatus", Convert.ToInt32(RecordStatus.Active), DbType.Int32, ParameterDirection.Input);


                    if (locationCountry.LocationId == 0)
                    {
                        p.Add("@ActionType", ActionType.AddLocationCountry.ToString(), DbType.String, ParameterDirection.Input);
                    }
                    else
                    {
                        p.Add("@ActionType", ActionType.UpdateLocationCountry.ToString(), DbType.String, ParameterDirection.Input);
                    }

                    result = db.Execute("usp_CRED_LocationCountry", p, commandType: CommandType.StoredProcedure);
                }

                return(Task.FromResult(result));
            }
        }
コード例 #2
0
        public void TestSubmitEmptyOrder()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <BaB_DbContext>()
                          .UseInMemoryDatabase(databaseName: "Test8Db")
                          .Options;

            //Act
            Customer testCustomer;

            #region Test database seeding
            using (var context = new BaB_DbContext(options))
            {
                #region Customers
                //Add customers to database for sampling from
                Customer testCustomer1 = new Customer
                {
                    CustFirstName = "Annie",
                    CustLastName  = "Admin",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                Customer testCustomer2 = new Customer
                {
                    CustFirstName = "Becky",
                    CustLastName  = "Boss",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                context.Add(testCustomer1);
                context.Add(testCustomer2);
                #endregion

                #region LocationCountry
                //Add Location Country to the test database
                LocationCountry testLocationCountry = new LocationCountry
                {
                    Country = "USA"
                };

                context.Add(testLocationCountry);
                #endregion

                #region LocationState
                //Add Location State to the test database
                LocationState testLocationState = new LocationState
                {
                    State = "Illinois"
                };

                context.Add(testLocationState);
                #endregion

                #region Locations
                //Add locations to the test database
                Location testLocation1 = new Location
                {
                    LocationAddress = "1 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                Location testLocation2 = new Location
                {
                    LocationAddress = "2 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                context.Add(testLocation1);
                context.Add(testLocation2);
                #endregion

                testCustomer = testCustomer1;

                context.SaveChanges();
            }
            #endregion

            PlaceOrder testPlaceOrder = new PlaceOrder();

            using (var context = new BaB_DbContext(options))
            {
                testPlaceOrder.CreateOrder(new UnitTest8Inputs(), context, testCustomer);
            }

            //Assert
            using (var context = new BaB_DbContext(options))
            {
                Assert.Equal(0, context.OrderLineItemsDB.Count());
            }
        }
コード例 #3
0
        public void TestOrderLookupCustomerLastName()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <BaB_DbContext>()
                          .UseInMemoryDatabase(databaseName: "Test7DB")
                          .Options;

            //Act
            Order testOrder;

            #region Test database seeding
            using (var context = new BaB_DbContext(options))
            {
                #region Customers
                //Add customers to database for sampling from
                Customer testCustomer1 = new Customer
                {
                    CustFirstName = "Annie",
                    CustLastName  = "Admin",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                Customer testCustomer2 = new Customer
                {
                    CustFirstName = "Becky",
                    CustLastName  = "Boss",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                context.Add(testCustomer1);
                context.Add(testCustomer2);
                #endregion

                #region Products
                //Add a product to the database for building with
                Product testProduct = new Product
                {
                    ProductName  = "Test product",
                    ProductPrice = 1
                };
                context.Add(testProduct);
                #endregion

                #region LocationCountry
                //Add Location Country to the test database
                LocationCountry testLocationCountry = new LocationCountry
                {
                    Country = "USA"
                };

                context.Add(testLocationCountry);
                #endregion

                #region LocationState
                //Add Location State to the test database
                LocationState testLocationState = new LocationState
                {
                    State = "Illinois"
                };

                context.Add(testLocationState);
                #endregion

                #region Locations
                //Add locations to the test database
                Location testLocation1 = new Location
                {
                    LocationAddress = "1 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                Location testLocation2 = new Location
                {
                    LocationAddress = "2 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                context.Add(testLocation1);
                context.Add(testLocation2);
                #endregion

                #region Orders
                //Add orders to the database for testing
                Order testOrder1 = new Order
                {
                    OrderCustomer = testCustomer1,
                    OrderLocation = testLocation2,
                    OrderDate     = DateTime.Now,
                    //OrderTotal = 3
                };

                Order testOrder2 = new Order
                {
                    OrderCustomer = testCustomer2,
                    OrderLocation = testLocation1,
                    OrderDate     = DateTime.Now,
                    //OrderTotal = 7
                };

                context.Add(testOrder1);
                context.Add(testOrder2);
                #endregion

                #region Line Items
                //Add line items to the database for building with
                OrderLineItem testLineItem1 = new OrderLineItem
                {
                    LineItemOrder   = testOrder1,
                    LineItemProduct = testProduct,
                    Quantity        = 1,
                    LinePrice       = 1
                };

                OrderLineItem testLineItem2 = new OrderLineItem
                {
                    LineItemOrder   = testOrder1,
                    LineItemProduct = testProduct,
                    Quantity        = 2,
                    LinePrice       = 2
                };

                OrderLineItem testLineItem3 = new OrderLineItem
                {
                    LineItemOrder   = testOrder2,
                    LineItemProduct = testProduct,
                    Quantity        = 3,
                    LinePrice       = 3
                };

                OrderLineItem testLineItem4 = new OrderLineItem
                {
                    LineItemOrder   = testOrder2,
                    LineItemProduct = testProduct,
                    Quantity        = 4,
                    LinePrice       = 4
                };

                context.Add(testLineItem1);
                context.Add(testLineItem2);
                context.Add(testLineItem3);
                context.Add(testLineItem4);
                #endregion

                //fill in testOrder with one of the pre-seeded values
                testOrder = testOrder1;

                context.SaveChanges();
            }
            #endregion

            //Create object to hold the OrderLookup reference
            SearchPastOrders testOrderLookupObject = new SearchPastOrders();

            using (var context = new BaB_DbContext(options))
            {
                testOrderLookupObject.OrderLookup(new UnitTest7Inputs(), context);
            }

            //Assert
            using (var context = new BaB_DbContext(options))
            {
                Assert.Equal(testOrder.OrderID, testOrderLookupObject.QueriedOrder.OrderID);
            }
        }
コード例 #4
0
        public void TestRemoveItemFromOrder()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <BaB_DbContext>()
                          .UseInMemoryDatabase(databaseName: "Test10Db")
                          .Options;

            //Act
            Customer testCustomer;

            #region Test database seeding
            using (var context = new BaB_DbContext(options))
            {
                #region Customers
                //Add customers to database for sampling from
                Customer testCustomer1 = new Customer
                {
                    CustFirstName = "Annie",
                    CustLastName  = "Admin",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                Customer testCustomer2 = new Customer
                {
                    CustFirstName = "Becky",
                    CustLastName  = "Boss",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                context.Add(testCustomer1);
                context.Add(testCustomer2);
                #endregion

                #region LocationCountry
                //Add Location Country to the test database
                LocationCountry testLocationCountry = new LocationCountry
                {
                    Country = "USA"
                };

                context.Add(testLocationCountry);
                #endregion

                #region LocationState
                //Add Location State to the test database
                LocationState testLocationState = new LocationState
                {
                    State = "Illinois"
                };

                context.Add(testLocationState);
                #endregion

                #region Products
                //Add a product to the database for building with
                Product testProduct1 = new Product
                {
                    ProductName  = "Test product 1",
                    ProductPrice = 1
                };

                Product testProduct2 = new Product
                {
                    ProductName  = "Test product 2",
                    ProductPrice = 1
                };

                Product testProduct3 = new Product
                {
                    ProductName  = "Test product 3",
                    ProductPrice = 1
                };

                context.Add(testProduct1);
                context.Add(testProduct2);
                context.Add(testProduct3);
                #endregion

                #region Locations
                //Add locations to the test database
                Location testLocation1 = new Location
                {
                    LocationAddress = "1 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                Location testLocation2 = new Location
                {
                    LocationAddress = "2 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                context.Add(testLocation1);
                context.Add(testLocation2);
                #endregion

                #region Inventory
                //Add inventory to locations
                Inventory testInventory1 = new Inventory
                {
                    InventoryLocation = testLocation1,
                    InventoryProduct  = testProduct1,
                    QuantityAvailable = 15
                };

                Inventory testInventory2 = new Inventory
                {
                    InventoryLocation = testLocation1,
                    InventoryProduct  = testProduct2,
                    QuantityAvailable = 15
                };

                Inventory testInventory3 = new Inventory
                {
                    InventoryLocation = testLocation1,
                    InventoryProduct  = testProduct3,
                    QuantityAvailable = 15
                };

                Inventory testInventory4 = new Inventory
                {
                    InventoryLocation = testLocation2,
                    InventoryProduct  = testProduct1,
                    QuantityAvailable = 15
                };

                Inventory testInventory5 = new Inventory
                {
                    InventoryLocation = testLocation2,
                    InventoryProduct  = testProduct2,
                    QuantityAvailable = 15
                };

                Inventory testInventory6 = new Inventory
                {
                    InventoryLocation = testLocation2,
                    InventoryProduct  = testProduct3,
                    QuantityAvailable = 15
                };

                context.Add(testInventory1);
                context.Add(testInventory2);
                context.Add(testInventory3);
                context.Add(testInventory4);
                context.Add(testInventory5);
                context.Add(testInventory6);
                #endregion

                testCustomer = testCustomer1;

                context.SaveChanges();
            }
            #endregion

            PlaceOrder testPlaceOrder = new PlaceOrder();

            using (var context = new BaB_DbContext(options))
            {
                testPlaceOrder.CreateOrder(new UnitTest11Inputs(), context, testCustomer);
            }

            //Assert
            using (var context = new BaB_DbContext(options))
            {
                Assert.Equal(0, context.OrderLineItemsDB.Count());
                Assert.Equal(0, context.OrdersDB.Count());
            }
        }
コード例 #5
0
 public async Task <int> PostLocationCountry(LocationCountry locationCountry)
 {
     return(await locationCountryServiceobj.PostLocationCountry(locationCountry));
 }
コード例 #6
0
 public Task <int> PostLocationCountry(LocationCountry locationCountry)
 {
     return(locationCountryRepositoryobj.PostLocationCountry(locationCountry));
 }
コード例 #7
0
        protected override void UnpackResponse()
        {
            base.UnpackResponse();

            MemoryStream responseStream = new MemoryStream(m_responsePayload);
            BinaryReader responseReader = new BinaryReader(responseStream, Encoding.Unicode);

            if (responseStream.Length < MinResponseMessageLenght)
            {
                throw new MessageWrongSizeException("Get Player Location City, State, Code and Country List");
            }



            try
            {
                responseReader.BaseStream.Seek(sizeof(int), SeekOrigin.Begin);

                ushort countCity = responseReader.ReadUInt16();
                CityList.Clear();
                for (ushort x = 0; x < countCity; x++)
                {
                    LocationCity code      = new LocationCity();
                    ushort       stringLen = responseReader.ReadUInt16();
                    code.City = new string(responseReader.ReadChars(stringLen));
                    CityList.Add(code);
                }
                GetPlayerLocationPer.CityName = CityList;


                ushort countZipCode = responseReader.ReadUInt16();
                ZipCodeList.Clear();
                for (ushort x = 0; x < countZipCode; x++)
                {
                    LocationZipCode code      = new LocationZipCode();
                    ushort          stringlen = responseReader.ReadUInt16();
                    code.ZipCode = new string(responseReader.ReadChars(stringlen));

                    ZipCodeList.Add(code);
                }
                GetPlayerLocationPer.ZipCodeName = ZipCodeList;


                ushort countState = responseReader.ReadUInt16();
                StateList.Clear();
                for (ushort x = 0; x < countState; x++)
                {
                    LocationState code      = new LocationState();
                    ushort        stringLen = responseReader.ReadUInt16();
                    code.State = new string(responseReader.ReadChars(stringLen));
                    StateList.Add(code);
                }
                GetPlayerLocationPer.StateName = StateList;


                ushort countCountry = responseReader.ReadUInt16();
                CountryList.Clear();
                for (ushort x = 0; x < countCountry; x++)
                {
                    LocationCountry code      = new LocationCountry();
                    ushort          stringLen = responseReader.ReadUInt16();
                    code.Country = new string(responseReader.ReadChars(stringLen));

                    CountryList.Add(code);
                }
                GetPlayerLocationPer.CountryName = CountryList;
            }
            catch (EndOfStreamException e)
            {
                throw new MessageWrongSizeException("Get Player Location City, State, Code and Country List", e);
            }
            catch (Exception e)
            {
                throw new ServerException("Get Player Location City, State, Code and Country List", e);
            }
            responseReader.Close();
        }