Exemplo n.º 1
0
        public async Task GET_Returns_Ordered_List()
        {
            var controller = new RegionsController(Context);

            base.ConfigureRequest(controller);

            Context.Regions.Add(new Region
            {
                Id   = Guid.NewGuid(),
                Name = "My Custom Region"
            });

            Context.Regions.Add(new Region
            {
                Id   = Guid.NewGuid(),
                Name = "A different name"
            });

            Context.SaveChanges();

            var orderedList = await GetData <List <RegionModel> >(controller.Get(true));

            Assert.AreEqual(2, orderedList.Count());
            Assert.AreNotEqual(Guid.Empty, orderedList.First().Id);
            Assert.AreNotEqual(Guid.Empty, orderedList.Last().Id);
            Assert.AreEqual("A different name", orderedList.First().Name);
            Assert.AreEqual("My Custom Region", orderedList.Last().Name);
        }
Exemplo n.º 2
0
        public async Task GET_Is_OK()
        {
            var controller = new RegionsController(Context);

            ConfigureRequest(controller);

            var result = await GetResponse(controller.Get(true));

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
        public void TestRegionsControllerGetAll()
        {
            // Arrange
            RegionsController controller = new RegionsController();

            // Act
            var result = controller.Get();

            // Assert
            Assert.IsTrue(result.Any());
        }
Exemplo n.º 4
0
        public async Task GET_Returns_List()
        {
            var controller = new RegionsController(Context);

            base.ConfigureRequest(controller);

            // Act
            var result = await GetData <List <RegionModel> >(controller.Get(true));

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
Exemplo n.º 5
0
        public void GetReturnsListOfRegions()
        {
            //Arrange
            var moq = new Mock <IRegionsRepository>();

            moq.Setup(m => m.Get()).Returns(Task.FromResult(new List <Region>() as IEnumerable <Region>));
            RegionsController controller = new RegionsController(moq.Object);

            //Act
            var result = controller.Get().Result;

            //Assert
            Assert.IsInstanceOfType(result, typeof(IEnumerable <Region>));
        }
Exemplo n.º 6
0
        public async Task GET_Returns_Nested_Stations()
        {
            var controller = new RegionsController(Context);

            base.ConfigureRequest(controller);

            var region = new Region
            {
                Id   = Guid.NewGuid(),
                Name = "My Custom Region"
            };

            Context.Regions.Add(region);
            Context.SaveChanges();

            Context.Stations.Add(new Station
            {
                Id   = Guid.NewGuid(),
                Name = "My Station",
                IsMarkedAsDeleted = false,
                RegionId          = region.Id
            });

            Context.Stations.Add(new Station
            {
                Id   = Guid.NewGuid(),
                Name = "An Ordered Station",
                IsMarkedAsDeleted = false,
                RegionId          = region.Id
            });

            Context.Stations.Add(new Station
            {
                Id   = Guid.NewGuid(),
                Name = "My Deleted Station",
                IsMarkedAsDeleted = true,
                RegionId          = region.Id
            });
            Context.SaveChanges();

            var orderedList = await GetData <List <RegionModel> >(controller.Get(false));

            Assert.AreEqual(2, orderedList[0].Stations.Count());
            Assert.AreEqual("An Ordered Station", orderedList[0].Stations.First().Name);
            Assert.AreEqual("My Station", orderedList[0].Stations.Last().Name);
        }
Exemplo n.º 7
0
        public void GetIdReturnsRegion()
        {
            //Arrange
            var moq = new Mock <IRegionsRepository>();

            moq.Setup(m => m.Get(It.IsAny <object[]>())).Returns <object[]>(id => Task.FromResult(new Region {
                Id = (int)id[0]
            }));
            RegionsController controller = new RegionsController(moq.Object);
            int regionId = 3;

            //Act
            var result = controller.Get(regionId).Result;

            //Assert
            Assert.IsInstanceOfType(result, typeof(Region));
            Assert.AreEqual(regionId, result.Id);
        }