Beispiel #1
0
        public List Post(string name)
        {
            var list = new List()
            {
                Name        = name,
                DateCreated = DateTime.Now,
                IsDeleted   = false
            };

            return(_listRepo.Add(list));
        }
        public async Task Add_ShouldNotThrow_WhenBeingIterated()
        {
            //Arrange
            ListRepository <string> repository = new ListRepository <string>();
            var numItems = 1000;

            for (var i = 0; i < numItems; ++i)
            {
                repository.Add($"OriginalItem_{i}");
            }

            //Act - Begin iterating on one thread
            var iterationTask = Task.Run(() =>
            {
                var remainingIterations = 10000;
                while (remainingIterations > 0)
                {
                    foreach (var item in repository)
                    {
                        //keep iterating
                    }
                    --remainingIterations;
                }
            });

            //Act - Insert on another thread
            var addTask = Task.Run(() =>
            {
                for (var i = 0; i < numItems; ++i)
                {
                    repository.Add($"NewItem_{i}");
                }
            });

            //Assert that this does not throw.  Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
            Assert.DoesNotThrowAsync(async() =>
            {
                await Task.WhenAll(new Task[] { iterationTask, addTask });
            });
        }
        public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd()
        {
            // Arrange
            IRepository <string> repository = new ListRepository <string>();

            // Act
            var itemName = "newItem";

            repository.Add(itemName);
            var result = repository.Contains(itemName);

            // Assert
            Assert.IsTrue(result);
        }
Beispiel #4
0
        public void ListRepository_Add_IsNotNullWhenGet()
        {
            var dbData = new DalList
            {
                Id = 100,
                Description = "aaa",
                Title = "aaa"
            };
            var dbSetMock = new Mock<DbSet<OrmList>>();
            var dbContextMock = new Mock<EntityModelContext>();
            dbContextMock.Setup(x => x.Set<OrmList>()).Returns(dbSetMock.Object);

            var repo = new ListRepository(dbContextMock.Object);
            repo.Add(dbData);
            Assert.IsNotNull(repo.Get(100));
        }
Beispiel #5
0
        public void ListRepository_Add_IsNotNullWhenGet()
        {
            var dbData = new DalList
            {
                Id          = 100,
                Description = "aaa",
                Title       = "aaa"
            };
            var dbSetMock     = new Mock <DbSet <OrmList> >();
            var dbContextMock = new Mock <EntityModelContext>();

            dbContextMock.Setup(x => x.Set <OrmList>()).Returns(dbSetMock.Object);

            var repo = new ListRepository(dbContextMock.Object);

            repo.Add(dbData);
            Assert.IsNotNull(repo.Get(100));
        }
 public IActionResult Post(List list)
 {
     _listRepository.Add(list);
     return(CreatedAtAction("Get", new { id = list.Id }, list));
 }