Esempio n. 1
0
        public async Task GetList_ShouldCallListRepositoryGet()
        {
            // Data
            var listModel = new ListModel {
                Name = "todo list"
            };
            var listEntity = new Data.Entities.List {
                Name = "todo list"
            };
            IEnumerable <Data.Entities.List> lists = new List <Data.Entities.List>
            {
                listEntity
            };

            // Setup
            _mockListRepository.Setup(x => x.Get(listModel.Id, listModel.UserId, listModel.Name))
            .Returns(Task.FromResult(lists)).Verifiable();

            // Test
            var listService = new ListService(_mockListRepository.Object);
            await listService.GetList(listModel);

            // Analysis
            _mockListRepository.Verify();
        }
Esempio n. 2
0
        public IActionResult GetList([FromRoute] int id)
        {
            try
            {
                var list = listService.GetList(id);

                if (list == null)
                {
                    throw new Exception("Error. List not found");
                }

                return(Ok(list));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
        public ActionResult Show(string ownerScreenName, string listSlug)
        {
            var service = new ListService(Token);
            var list    = service.GetList(ownerScreenName, listSlug);

            if (list == null)
            {
                return(NotFound());
            }

            //will throw in view exception handled normally
            ViewData["loadInitialData"] =
                new Func <string>(
                    () =>
                    new JavaScriptSerializer().Serialize(service.GetStatuses(ownerScreenName, listSlug, null, null)));

            return(View(list));
        }
Esempio n. 4
0
        public async Task General()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "TodoDB")
                          .Options;

            using (var db = new ApplicationDbContext(options))
            {
                var listService = new ListService(db);

                var userId        = Guid.NewGuid().ToString();
                var anotherUserId = Guid.NewGuid().ToString();

                string Name1 = "Testname";
                string Name2 = "Testname2";

                var model = new ListModel()
                {
                    OwnerId = userId,
                    Name    = Name1
                };

                await listService.AddList(model);

                var lists = await listService.GetLists(anotherUserId);

                Assert.AreEqual(lists.Count(), 0);

                lists = await listService.GetLists(userId);

                Assert.AreEqual(lists.Count(), 1);

                model.Name = Name2;
                await listService.AddList(model);

                lists = await listService.GetLists(anotherUserId);

                Assert.AreEqual(lists.Count(), 0);

                lists = await listService.GetLists(userId);

                Assert.AreEqual(lists.Count(), 2);

                var list = await listService.GetList(lists.First().Id);

                Assert.IsTrue(list != null);

                await listService.DeleteList(lists.First().Id);

                lists = await listService.GetLists(anotherUserId);

                Assert.AreEqual(lists.Count(), 0);

                lists = await listService.GetLists(userId);

                Assert.AreEqual(lists.Count(), 1);

                await listService.DeleteList(lists.First().Id);

                lists = await listService.GetLists(anotherUserId);

                Assert.AreEqual(lists.Count(), 0);

                lists = await listService.GetLists(userId);

                Assert.AreEqual(lists.Count(), 0);
            }
        }
Esempio n. 5
0
        private Boolean BreakAwayImmediateEx(String server, Int32 txList, Int32 baList, IEnumerable <EventDTO> baContent)
        {
            var      brDuration = TimeCode.Empty;
            var      brSom      = TimeCode.Empty;
            TimeCode brokenEventDur;
            var      res         = false;
            var      chStatus    = GetBreakAwayListStatus(server, txList);
            var      minFragment = GetMinFragmentForChannel(server, txList);

            var brokenEventPosition = GetOnAirEventPosition(server, txList, out brokenEventDur);

            if (brokenEventPosition != Guid.Empty)
            {
                chStatus.InBreakAway = true;
                var commandTime  = GetServerTimeCode(server, txList);
                var baLatency    = new TimeCode(commandTime.FrameRate, commandTime.DropFrame, _breakAwayLatency);
                var remainingDur = new TimeCode(commandTime.FrameRate, commandTime.DropFrame, brokenEventDur.Hour,
                                                brokenEventDur.Minute, brokenEventDur.Second, brokenEventDur.Frame);

                var targetEv = GetEventByPosition(server, txList, brokenEventPosition);
                if (targetEv != null)
                {
                    var savedDuration  = targetEv.Duration.ToTimeCode(commandTime.FrameRate, commandTime.DropFrame);
                    var baOnUpcount    = targetEv.EventControl.Contains(EventControlType.AutoUpcount);
                    var divideRequired = false;
                    var bawayTime      = TimeCode.Empty;
                    if (baOnUpcount)
                    {
                        bawayTime      = commandTime + baLatency;
                        brDuration     = savedDuration;
                        brSom          = new TimeCode(commandTime.FrameRate, commandTime.DropFrame, 0, 0, 0, 0);
                        divideRequired = true;
                    }
                    else
                    {
                        if (remainingDur > baLatency + minFragment)
                        {
                            bawayTime      = commandTime + baLatency;
                            brDuration     = remainingDur - baLatency;
                            brSom          = savedDuration + remainingDur + baLatency;
                            divideRequired = true;
                        }
                        if (remainingDur == (baLatency + minFragment))
                        {
                            bawayTime      = commandTime + baLatency;
                            brDuration     = remainingDur - baLatency;
                            brSom          = savedDuration - remainingDur + baLatency;
                            divideRequired = true;
                        }
                        if (remainingDur < baLatency + minFragment ||
                            remainingDur == baLatency)
                        {
                            bawayTime      = commandTime + remainingDur;
                            divideRequired = false;
                        }
                        if (remainingDur < baLatency)
                        {
                            targetEv = GetNextPrimaryEvent(server, txList, brokenEventPosition);
                            if (targetEv != null)
                            {
                                brokenEventDur = targetEv.Duration.ToTimeCode(commandTime.FrameRate, commandTime.DropFrame);
                            }
                            bawayTime = commandTime + baLatency;
                            var tempMoment = commandTime + remainingDur + minFragment;
                            if (tempMoment > bawayTime)
                            {
                                //FHtemp1, FHtemp2 - durations for determination breakaway point.
                                var fHtemp1 = commandTime + remainingDur + minFragment;
                                var fHtemp2 = commandTime + remainingDur + brokenEventDur;
                                if (fHtemp1 < fHtemp2)
                                {
                                    bawayTime      = tempMoment;
                                    brDuration     = brokenEventDur + minFragment;
                                    brSom          = minFragment;
                                    divideRequired = true;
                                }
                                else
                                {
                                    bawayTime      = fHtemp2;
                                    divideRequired = false;
                                }
                            }
                        }
                    }

                    Guid nextPrimaryPosition;
                    if (divideRequired)
                    {
                        // if dividing current playing event
                        if (!VerifyAOAttribute(server, txList, baList, brokenEventPosition))
                        {
                            return(false);
                        }
                        nextPrimaryPosition = GetNextPrimaryEvent(server, txList, brokenEventPosition).AdcEventId;
                        if (!PerformBreakAwayFastBackUp(server, txList, nextPrimaryPosition, baList))
                        {
                            return(false);
                        }

                        // calculations
                        targetEv = GetEventByPosition(server, txList, brokenEventPosition);
                        if (targetEv != null)
                        {
                            targetEv.EventStatus.ToList().Clear();
                            targetEv.Duration = new TimeCodeDTO(brDuration);

                            // brSOM contains value to which the original event's SOM should be shifted.
                            // brSOM is not event's new SOM, it should be added to original SOM
                            var origSom = targetEv.Som.ToTimeCode(commandTime.FrameRate, commandTime.DropFrame);
                            if (origSom != TimeCode.Empty)
                            {
                                brSom += origSom;
                            }
                            targetEv.Som = new TimeCodeDTO(brSom);
                            if (!InsertEvent(server, baList, targetEv, InsertPlaceType.AtListBegin, Guid.Empty))
                            {
                                return(false);
                            }
                        }
                        var previousPrimary = GetPreviousPrimaryEvent(server, txList, nextPrimaryPosition);
                        brokenEventPosition = previousPrimary != null ? previousPrimary.AdcEventId : nextPrimaryPosition;
                        if (!PerformListThread(server, baList))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        // if we should start from next primary event
                        nextPrimaryPosition = GetNextPrimaryEvent(server, txList, brokenEventPosition).AdcEventId;
                        VerifyAOAttribute(server, txList, baList, nextPrimaryPosition);
                        if (!PerformBreakAwayFastBackUp(server, txList, nextPrimaryPosition, baList))
                        {
                            return(false);
                        }
                        brokenEventPosition = GetPreviousPrimaryEvent(server, txList, nextPrimaryPosition).AdcEventId;
                    }

                    //Insert the Ba content to the transmission list
                    var tmpBaList = baContent.ToList();
                    var insertedBreakAwayContent = InsertEventList(server, txList, InsertPlaceType.AtListEnd, tmpBaList,
                                                                   Guid.Empty);
                    var first = insertedBreakAwayContent.FirstOrDefault();
                    if (first == null)
                    {
                        return(false);
                    }
                    AppendAOAttribute(server, txList, bawayTime, first);

                    if (!GetSaveAOAttribute(server, txList))
                    {
                        // the first event in the ba list arrives with a delay (because of subscribe logic)
                        var attempts = 20;
                        while (attempts-- > 0)
                        {
                            Thread.Sleep(50);
                            var ev = _listService.GetList(_loginSession, server, baList).FirstOrDefault();
                            if (ev != null)
                            {
                                AppendAOAttribute(server, baList, bawayTime, ev);
                                break;
                            }
                        }
                    }

                    AddCommentEvent(server, txList, CommentIds.BreakAway, CommentTypes.Immediate, brokenEventPosition);

                    if (!PerformListUnThread(server, baList))
                    {
                        return(false);
                    }
                    if (!PerformListThread(server, baList))
                    {
                        return(false);
                    }
                    res = true;
                }
            }

            return(res);
        }
Esempio n. 6
0
        public ActionResult <List> Get(string id)
        {
            var list = _listService.GetList(id);

            return(list);
        }