当前位置: 首页>>代码示例>>C#>>正文


C# DataService.PostBeer方法代码示例

本文整理汇总了C#中DataService.PostBeer方法的典型用法代码示例。如果您正苦于以下问题:C# DataService.PostBeer方法的具体用法?C# DataService.PostBeer怎么用?C# DataService.PostBeer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataService的用法示例。


在下文中一共展示了DataService.PostBeer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoLiveCycle

        public void DoLiveCycle()
        {
            Task.Run(async () =>
            {
                //arrange
                await ApiTestHelper.CreateTestUser(ApiTestHelper.TestUserGuid);
                var ds = new DataService();
                var beer1 = new BeerEntity()
                {
                    Guid = Guid.NewGuid(),
                    DrinkTime = DateTime.Now - TimeSpan.FromDays(2)
                };
                var beer2 = new BeerEntity()
                {
                    Guid = Guid.NewGuid(),
                    DrinkTime = DateTime.Now - TimeSpan.FromDays(1)
                };
                var beer3 = new BeerEntity()
                {
                    Guid = Guid.NewGuid(),
                    DrinkTime = DateTime.Now
                };

                var add = new BeerRequest(PossibleActions.Add, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer1, beer2, beer3
                    }
                };
                var remove1 = new BeerRequest(PossibleActions.Remove, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer1, beer3
                    }
                };
                var remove2 = new BeerRequest(PossibleActions.Remove, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer2
                    }
                };

                //act
                //check if 0 beers
                var beers = await ds.GetBeers(ApiTestHelper.TestUserGuid);
                ApiAssertHelper.CheckBaseResponse(beers);
                Assert.IsTrue(beers.Beers == null || !beers.Beers.Any());

                //add beers;
                var res = await ds.PostBeer(add);
                ApiAssertHelper.CheckBooleanResponse(res);
                
                //check if 3 beers
                beers = await ds.GetBeers(ApiTestHelper.TestUserGuid);
                ApiAssertHelper.CheckBaseResponse(beers);
                Assert.IsTrue(beers.Beers != null && beers.Beers.Count == 3);

                //remove 2 beers;
                res = await ds.PostBeer(remove1);
                ApiAssertHelper.CheckBooleanResponse(res);

                //check if 1 beer, check Date
                beers = await ds.GetBeers(ApiTestHelper.TestUserGuid);
                ApiAssertHelper.CheckBaseResponse(beers);
                Assert.IsTrue(beers.Beers != null && beers.Beers.Count == 1);
                Assert.IsTrue(beers.Beers[0].Guid == beer2.Guid);
                Assert.IsTrue(beers.Beers[0].DrinkTime - beer2.DrinkTime < TimeSpan.FromSeconds(1));

                //remove 2 invalid beers;
                res = await ds.PostBeer(remove1);
                ApiAssertHelper.CheckBooleanResponse(res);

                //remove 1 beer left;
                res = await ds.PostBeer(remove2);
                ApiAssertHelper.CheckBooleanResponse(res);

                //check if 0 beers
                beers = await ds.GetBeers(ApiTestHelper.TestUserGuid);
                ApiAssertHelper.CheckBaseResponse(beers);
                Assert.IsTrue(beers.Beers == null || !beers.Beers.Any());
                
                //clean
                await ApiTestHelper.DeleteTestUser(ApiTestHelper.TestUserGuid);
            }).GetAwaiter().GetResult();
        }
开发者ID:famoser,项目名称:BeerCompanion,代码行数:88,代码来源:BeerRequests.cs

示例2: TestSync

        public void TestSync()
        {
            Task.Run(async () =>
            {
                //arrange
                await ApiTestHelper.CreateTestUser(ApiTestHelper.TestUserGuid);
                var ds = new DataService();
                var beer1 = new BeerEntity()
                {
                    Guid = Guid.NewGuid(),
                    DrinkTime = DateTime.Now - TimeSpan.FromDays(2)
                };
                var beer2 = new BeerEntity()
                {
                    Guid = Guid.NewGuid(),
                    DrinkTime = DateTime.Now - TimeSpan.FromDays(1)
                };
                var beer3 = new BeerEntity()
                {
                    Guid = Guid.NewGuid(),
                    DrinkTime = DateTime.Now
                };
                var beer4 = new BeerEntity()
                {
                    Guid = Guid.NewGuid(),
                    DrinkTime = DateTime.Now + TimeSpan.FromDays(1)
                };

                var add = new BeerRequest(PossibleActions.Add, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer1, beer2, beer3
                    }
                };
                var remove = new BeerRequest(PossibleActions.Remove, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer1, beer3, beer2
                    }
                };

                var correct1 = new BeerRequest(PossibleActions.Sync, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer3
                    }
                };
                var correct2 = new BeerRequest(PossibleActions.Sync, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer3, beer2, beer1
                    }
                };
                var false1 = new BeerRequest(PossibleActions.Sync, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer1, beer2
                    }
                };
                var false2 = new BeerRequest(PossibleActions.Sync, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {

                    }
                };
                var false3 = new BeerRequest(PossibleActions.Sync, ApiTestHelper.TestUserGuid)
                {
                    Beers = new List<BeerEntity>()
                    {
                        beer1, beer2,beer4
                    }
                };
                var res = await ds.PostBeer(add);
                ApiAssertHelper.CheckBooleanResponse(res);


                //act
                res = await ds.PostBeer(correct1);
                ApiAssertHelper.CheckBooleanResponse(res);

                res = await ds.PostBeer(correct2);
                ApiAssertHelper.CheckBooleanResponse(res);

                res = await ds.PostBeer(false1);
                ApiAssertHelper.CheckBooleanResponseForFalse(res);

                res = await ds.PostBeer(false2);
                ApiAssertHelper.CheckBooleanResponseForFalse(res);

                res = await ds.PostBeer(false3);
                ApiAssertHelper.CheckBooleanResponseForFalse(res);

                //clean
                await ds.PostBeer(remove);
//.........这里部分代码省略.........
开发者ID:famoser,项目名称:BeerCompanion,代码行数:101,代码来源:BeerRequests.cs


注:本文中的DataService.PostBeer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。