コード例 #1
0
        public void GetAllOnEmptyRepositoryShouldReturnEmptyTest()
        {
            var timeZoneService = new TimeZoneService(new MockTimeZoneRepository());
            var allItems        = timeZoneService.GetAll();

            Assert.AreEqual(allItems.Count(), 0);
        }
コード例 #2
0
        // GET api/<controller>
        public IHttpActionResult Get()
        {
            try
            {
                IEnumerable <TimeZoneDTO> items = new List <TimeZoneDTO>();
                var timeZoneService             = new TimeZoneService(new TimeZoneRepository());

                if (User.IsInRole("Admin"))
                {
                    items = timeZoneService.GetAll();
                }
                else if (User.IsInRole("User"))
                {
                    items = timeZoneService.GetByOwner(User.Identity.Name);
                }
                else
                {
                    return(InternalServerError());
                }

                return(Ok(items));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
コード例 #3
0
        public void AddMultipleItemsTest()
        {
            var timeZoneService = new TimeZoneService(new MockTimeZoneRepository());

            timeZoneService.Add(GetMockTimeZone(1));
            timeZoneService.Add(GetMockTimeZone(2));
            timeZoneService.Add(GetMockTimeZone(3));

            Assert.AreEqual(timeZoneService.GetAll().Count(), 3);
        }