public async Task DeleteTest()
        {
            //Arrange
            using (var context = new AppDbContext(options))
            {
                var storage = new Storage {
                    Id = 1
                };
                var repo = new StorageRepository(context);

                //Act
                context.Storages.Add(storage);
                await repo.Delete(storage.Id);

                var expectedResult = 0;
                var actualResult   = context.Storages.Local.Count;

                //Assert
                Assert.AreEqual(expectedResult, actualResult);
            }
        }
示例#2
0
        IEnumerator TestRestAsync()
        {
            Terminal.LogImportant("TestRestAsync");

            var score = new Score
            {
                Points   = Strings.RandomNumber(100, 10000),
                Points2  = Strings.RandomNumber(100, 10000),
                UserName = Strings.RandomString(10),
            };

            // CREATE
            Terminal.Log("CREATE");
            // get task
            var result1 = Repository.Create(score);

            // wait for it
            yield return(StartCoroutine(result1.WaitRoutine()));

            // client error
            result1.ThrowIfFaulted();
            // server error
            if (result1.Result.hasError)
            {
                throw new Exception(result1.Result.error.message);
            }

            //GET
            Terminal.Log("GET 2");
            var result2B = Repository.Get <Score>(score.UserName, score.Points);

            yield return(StartCoroutine(result2B.WaitRoutine()));

            result2B.ThrowIfFaulted();
            if (result2B.Result.hasError)
            {
                throw new Exception(result2B.Result.error.message);
            }
            var score2 = result2B.Result.data;

            score2.Points += 100;

            //UPDATE
            Terminal.Log("UPDATE");
            var result3 = Repository.Update(score2);

            yield return(StartCoroutine(result3.WaitRoutine()));

            result3.ThrowIfFaulted();
            if (result3.Result.hasError)
            {
                throw new Exception(result3.Result.error.message);
            }
            var score3 = result3.Result.data;

            //COMPARE 2 and 3
            Assert.IsTrue(score.Points + 100 == score3.Points, "update did not get");

            //DELETE
            Terminal.Log("DELETE");
            var resultd = Repository.Delete(score3);

            yield return(StartCoroutine(resultd.WaitRoutine()));

            resultd.ThrowIfFaulted();
            if (resultd.Result.hasError)
            {
                throw new Exception(resultd.Result.error.message);
            }

            //GET 3
            Terminal.Log("GET 3");
            var result4 = Repository.Get <Score>(score.UserName, score.Points);

            yield return(StartCoroutine(result4.WaitRoutine()));

            result4.ThrowIfFaulted();
            if (result4.Result.hasError)
            {
                throw new Exception(result4.Result.error.message);
            }

            // INCR
            Terminal.Log("INCR");
            var result5 = Repository.Incr(score, "Points2");

            yield return(StartCoroutine(result5.WaitRoutine()));

            result5.ThrowIfFaulted();
            if (result5.Result.hasError)
            {
                throw new Exception(result5.Result.error.message);
            }
            Assert.IsTrue(result5.Result.data.Points2 > score.Points2, "Incr Failed");

            // DECR
            Terminal.Log("DECR");
            var result6 = Repository.Decr(score, "Points2", 2);

            yield return(StartCoroutine(result6.WaitRoutine()));

            result5.ThrowIfFaulted();
            if (result6.Result.hasError)
            {
                throw new Exception(result6.Result.error.message);
            }
            Assert.IsTrue(result6.Result.data.Points2 < score.Points2, "Decr failed");

            Terminal.LogSuccess("Test Success");
        }
 public ActionResult DeleteStorage(int id)
 {
     sRep.Delete(sRep.Find(id));
     return(RedirectToAction("StorageList"));
 }