コード例 #1
0
        public void ProductMappingListTest()
        {
            var options = new DbContextOptionsBuilder <FundstradingContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var ctx = new FundstradingContext(options))
            {
                ctx.Channel.Add(new Channel {
                    Description = "Description", Appid = "Appid", Apikey = "Apikey", Userid = "Userid", Baseurl = "Baseurl"
                });
                ctx.SaveChanges();
                ctx.Productmapping.Add(new Productmapping {
                    Incoming = "Incoming", Outgoing = "Outgoing", Channelid = ctx.Channel.FirstOrDefault().Id
                });
                ctx.SaveChanges();

                Assert.AreEqual(1, ctx.Channel.Count());
                Assert.AreEqual(1, ctx.Productmapping.Count());
            }

            // Use a clean instance of the context to run the test
            using (var ctx = new FundstradingContext(options))
            {
                ProductMappingRepository repo = new ProductMappingRepository(ctx);
                var task = repo.ProductMappingList();
                task.Wait();
                var results = task.Result.ToList();
                Assert.AreEqual(1, results.Count);                // got row
                Assert.AreEqual("Incoming", results[0].Incoming); // got field value
                Assert.IsNotNull(results[0].Channel);
            }
        }
コード例 #2
0
        public void UpdateProductMappingTest()
        {
            var options = new DbContextOptionsBuilder <FundstradingContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            Productmapping productMapping;
            Channel        channel2;

            // Insert seed data into the database using one instance of the context
            using (var ctx = new FundstradingContext(options))
            {
                Channel channel1 = new Channel {
                    Id = 1, Description = "Description", Appid = "Appid", Apikey = "Apikey", Userid = "Userid", Baseurl = "Baseurl"
                };
                channel2 = new Channel {
                    Id = 2, Description = "Description2", Appid = "Appid2", Apikey = "Apikey2", Userid = "Userid2", Baseurl = "Baseurl2"
                };

                ctx.Channel.Add(channel1);
                ctx.Channel.Add(channel2);
                ctx.SaveChanges();

                productMapping = new Productmapping {
                    Id = 1, Incoming = "Incoming", Outgoing = "Outgoing", Channelid = 1
                };

                ctx.Productmapping.Add(productMapping);
                ctx.SaveChanges();

                Assert.AreEqual(2, ctx.Channel.Count());
                Assert.AreEqual(1, ctx.Productmapping.Count());
            }

            // Use a clean instance of the context to run the test
            using (var ctx = new FundstradingContext(options))
            {
                ProductMappingRepository repo = new ProductMappingRepository(ctx);

                productMapping.Incoming = "I";
                productMapping.Outgoing = "O";
                productMapping.Channel  = channel2;

                repo.UpdateProductMapping(productMapping);
            }

            // Use a clean instance of the context to run the test
            using (var ctx = new FundstradingContext(options))
            {
                ProductMappingRepository repo = new ProductMappingRepository(ctx);

                var task = repo.FindProductMapping(1);
                task.Wait();
                Assert.IsNotNull(task.Result);
                Assert.AreEqual("I", task.Result.Incoming); // got field value
                Assert.AreEqual("O", task.Result.Outgoing); // got field value
                Assert.IsNotNull(task.Result.Channel);
                Assert.AreEqual(2, task.Result.Channelid);  // got field value
            }
        }
コード例 #3
0
        public void ChannelListTest()
        {
            var options = new DbContextOptionsBuilder <FundstradingContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var ctx = new FundstradingContext(options))
            {
                ctx.Channel.Add(new Channel {
                    Description = "Description", Appid = "Appid", Apikey = "Apikey", Userid = "Userid", Baseurl = "Baseurl"
                });
                ctx.SaveChanges();

                Assert.AreEqual(1, ctx.Channel.Count());
            }

            // Use a clean instance of the context to run the test
            using (var ctx = new FundstradingContext(options))
            {
                ProductMappingRepository repo = new ProductMappingRepository(ctx);
                var results = repo.ChannelList().ToList();
                Assert.AreEqual(1, results.Count);                      // got row
                Assert.AreEqual("Description", results[0].Description); // got field value
            }
        }
コード例 #4
0
        public void ChannelListTest()
        {
            Task.Run(async() =>
            {
                DateTime now = DateTime.Now;

                var options = new DbContextOptionsBuilder <FundstradingContext>()
                              .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                              .Options;

                // Insert seed data into the database using one instance of the context
                using (var ctx = new FundstradingContext(options))
                {
                    ctx.Channel.Add(new Channel {
                        Description = "Description", Appid = "Appid", Apikey = "Apikey", Userid = "Userid", Baseurl = "Baseurl"
                    });
                    ctx.SaveChanges();

                    Assert.AreEqual(1, ctx.Channel.Count());
                }

                // Use a clean instance of the context to run the test
                using (var ctx = new FundstradingContext(options))
                {
                    ProductMappingRepository repo = new ProductMappingRepository(ctx);
                    ProductMappingService productMappingservice = new ProductMappingService(repo);

                    var results     = productMappingservice.ChannelList();
                    var channelRows = results.ToList();

                    Assert.AreEqual(1, channelRows.Count);                      // got row
                    Assert.AreEqual("Description", channelRows[0].Description); // got field value
                }
            }).GetAwaiter().GetResult();
        }
コード例 #5
0
        public void FindProductMappingTest()
        {
            DateTime now = DateTime.Now;

            var options = new DbContextOptionsBuilder <FundstradingContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var ctx = new FundstradingContext(options))
            {
                ctx.Channel.Add(new Channel {
                    Description = "Description", Appid = "Appid", Apikey = "Apikey", Userid = "Userid", Baseurl = "Baseurl"
                });
                ctx.SaveChanges();
                ctx.Productmapping.Add(new Productmapping {
                    Id = 1, Incoming = "Incoming", Outgoing = "Outgoing", Channelid = ctx.Channel.FirstOrDefault().Id
                });
                ctx.SaveChanges();

                Assert.AreEqual(1, ctx.Channel.Count());
                Assert.AreEqual(1, ctx.Productmapping.Count());
            }

            // Use a clean instance of the context to run the test
            using (var ctx = new FundstradingContext(options))
            {
                ProductMappingRepository repo = new ProductMappingRepository(ctx);
                ProductMappingService    productMappingservice = new ProductMappingService(repo);

                var task = productMappingservice.FindProductMapping(1);
                task.Wait();
                Productmapping productMapping = task.Result;
                Assert.IsNotNull(productMapping);
                Assert.AreEqual(1, productMapping.Id);
                Assert.IsNotNull(productMapping.Channel);

                task = productMappingservice.FindProductMapping(2);
                task.Wait();
                productMapping = task.Result;
                Assert.IsNull(productMapping);
            }
        }