Esempio n. 1
0
        public void TimelineService_GetAllPublicTimelinesWithoutContentItems_Test()
        {
            // Arrange
            Mock <ITimelineDao> mock = new Mock <ITimelineDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.FindAllPublicTimelines()).Returns(new List <Timeline>()
            {
                new Timeline()
                {
                    Id        = 1,
                    Title     = "1ste wereld oorlog",
                    BeginDate = 1914M,
                    EndDate   = 1918M,
                    IsPublic  = true
                },
                new Timeline()
            });
            TimelineService target = new TimelineService(mock.Object, null);

            // Act
            IEnumerable <Timeline> result = target.GetAllPublicTimelinesWithoutContentItems();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
            Timeline firstResult = result.First();

            Assert.AreEqual((long)1, firstResult.Id);
            Assert.AreEqual("1ste wereld oorlog", firstResult.Title);
            Assert.AreEqual(1914M, firstResult.BeginDate);
            Assert.AreEqual(1918M, firstResult.EndDate);
            Assert.AreEqual(null, firstResult.RootContentItem);
            mock.Verify(verify => verify.FindAllPublicTimelines(), Times.Once);
        }
Esempio n. 2
0
    private IEnumerator _GetTimelinePosts()
    {
        AlertsService.makeLoadingAlert("Recebendo postagens");
        WWW postsRequest = TimelineService.GetTimelinePosts();

        while (!postsRequest.isDone)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        Debug.Log("Header: " + postsRequest.responseHeaders["STATUS"]);
        Debug.Log("Text: " + postsRequest.text);

        if (postsRequest.responseHeaders["STATUS"] == HTML.HTTP_200)
        {
            TimelineService.UpdateLocalPosts(postsRequest.text);

            START_POST_INDEX = 0;
            END_POST_INDEX   = (TimelineService.posts.Length < 5) ? TimelineService.posts.Length : 5;

            CreatePostsCards();
        }
        else
        {
            AlertsService.makeAlert("Falha na conexão", "Tente novamente mais tarde.", "");
            yield return(new WaitForSeconds(3f));

            LoadView("Home");
        }

        yield return(null);
    }
Esempio n. 3
0
        public ActionResult Index()
        {
            try
            {
                #region " [ Declaration ] "

                TimelineService   _timelineService   = new TimelineService();
                CetificateService _cetificateService = new CetificateService();

                ViewBag.timeline   = _timelineService.GetAll(UserID);
                ViewBag.cetificate = _cetificateService.GetAll(UserID);

                #endregion

                return(View());
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "Index", UserID, ex);
            }
        }
Esempio n. 4
0
        public void TimelineService_Add_Test()
        {
            // Arrange
            Mock <ITimelineDao> mock = new Mock <ITimelineDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.Add(It.IsAny <Timeline>()))
            .Callback((Timeline Timeline) => Timeline.Id = 123)
            .Returns((Timeline Timeline) => { return(Timeline); });
            Mock <IContentItemDao> contentItemMock = new Mock <IContentItemDao>(MockBehavior.Strict);
            TimelineService        target          = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            Timeline result = target.Add(new Timeline()
            {
                Title     = "1ste wereld oorlog",
                BeginDate = 1914M,
                EndDate   = 1918M
            });

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(123, result.Id);
            Assert.AreEqual("1ste wereld oorlog", result.Title);
            Assert.AreEqual(1914M, result.BeginDate);
            Assert.AreEqual(1918M, result.EndDate);
            mock.Verify(verify => verify.Add(It.IsAny <Timeline>()), Times.Once);
        }
Esempio n. 5
0
        public void TimelineService_Get_Test()
        {
            // Arrange
            Mock <ITimelineDao> mock = new Mock <ITimelineDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.Find(It.IsAny <long>())).Returns(new Timeline()
            {
                Id = 1,
                RootContentItemId = 123,
                Title             = "1ste wereld oorlog",
                BeginDate         = 1914M,
                EndDate           = 1918M
            });
            Mock <IContentItemDao> contentItemMock = new Mock <IContentItemDao>(MockBehavior.Strict);

            contentItemMock.Setup(setup => setup.Find(It.IsAny <long>(), It.IsAny <int>())).Returns(new ContentItem()
            {
                Children = new ContentItem[2]
            });
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            Timeline result = target.Get(1);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual((long)1, result.Id);
            Assert.AreEqual("1ste wereld oorlog", result.Title);
            Assert.AreEqual(1914M, result.BeginDate);
            Assert.AreEqual(1918M, result.EndDate);
            Assert.IsNotNull(result.RootContentItem);
            Assert.AreEqual(2, result.RootContentItem.Children.Count());
            mock.Verify(verify => verify.Find(It.IsAny <long>()), Times.Once);
            contentItemMock.Verify(verify => verify.Find(result.RootContentItemId, It.IsAny <int>()), Times.Once);
        }
Esempio n. 6
0
 public HomeController(UserManager <ApplicationUser> userManager,
                       TimelineService timeLine)
 {
     // Injecting the classes into the controller and assigning to variables.
     this._userManager = userManager;
     this._timeLine    = timeLine;
 }
    private IEnumerator _SendNewPost()
    {
        AlertsService.makeLoadingAlert("Enviando");

        int    userId      = UserService.user._id;
        string imageBase64 = camService.photoBase64,
               message     = newMessageField.text;

        WWW postForm = TimelineService.NewPost(userId, imageBase64, message);

        while (!postForm.isDone)
        {
            yield return(new WaitForSeconds(1f));
        }

        AlertsService.removeLoadingAlert();
        Debug.Log("Header: " + postForm.responseHeaders["STATUS"]);
        Debug.Log("Text: " + postForm.text);

        if (postForm.responseHeaders["STATUS"] == HTML.HTTP_200)
        {
            ReloadView();
        }
        else
        {
            AlertsService.makeAlert("Falha na conexão", "Ocorreu um problema ao enviar sua publicação. Tente novamente.", "Entendi");
        }

        yield return(null);
    }
Esempio n. 8
0
        public void ShowTimelineForCurrentWeek(DateTime date, params string[] tags)
        {
            DateTime start = date.AddDays((int)DayOfWeek.Sunday - (int)date.DayOfWeek);
            DateTime end   = date.AddDays((int)DayOfWeek.Saturday - (int)date.DayOfWeek);

            List <Timeline> timelines = TimelineService.GetTimelines(this.UserId, start, end, tags.ToList()).OrderBy(timeline => timeline.TimeStamp).ToList();

            SendTimelinesWeek(timelines);
        }
Esempio n. 9
0
        public async Task DownloadFile()
        {
            var mock = new Mock <IWebClientHelper>();

            var timeline = new TimelineService(BaseUrl, "ABC", "123", "cache", mock.Object);

            await timeline.DownloadFileAsync("http://www.upload.com/url", "testfilename.docx");

            mock.Verify(m => m.DownloadFileAsync("http://www.upload.com/url", "testfilename.docx"));
        }
Esempio n. 10
0
        public async Task GetJson500Error()
        {
            var mock = new Mock <IWebClientHelper>();

            mock.Setup(m => m.GetStatusCode(It.IsAny <WebResponse>())).Returns(HttpStatusCode.InternalServerError);
            mock.Setup(m => m.GetResponseMessage(It.IsAny <WebResponse>())).Returns("Internal server error");
            mock.Setup(m => m.DownloadStringAsync(It.IsAny <string>(), It.IsAny <NameValueCollection>())).Returns(TestUtils.GetExceptionTask <string>(new WebException("Hello")));

            var api = new TimelineService(BaseUrl, "ABC", "123", "cache", mock.Object);
            await api.GetJsonAsync("Test/Get");
        }
Esempio n. 11
0
        public void TimelineService_Get_Exception_Test()
        {
            // Arrange
            Mock <ITimelineDao>    mock            = new Mock <ITimelineDao>(MockBehavior.Strict);
            Mock <IContentItemDao> contentItemMock = new Mock <IContentItemDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.Find(It.IsAny <long>())).Throws(new Exception());
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            target.Get(1);
        }
Esempio n. 12
0
        public void TimelineService_Update_DontCatchException_Test()
        {
            // Arrange
            Mock <ITimelineDao> mock = new Mock <ITimelineDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.Update(It.IsAny <Timeline>())).Throws(new Exception());
            Mock <IContentItemDao> contentItemMock = new Mock <IContentItemDao>(MockBehavior.Strict);
            TimelineService        target          = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            target.Update(new Timeline());
        }
Esempio n. 13
0
        public void ShowTimelineForCurrentWeek()
        {
            DateTime currentDate = DateTime.Now;

            DateTime start = currentDate.AddDays((int)DayOfWeek.Sunday - (int)currentDate.DayOfWeek);
            DateTime end   = currentDate.AddDays((int)DayOfWeek.Saturday - (int)currentDate.DayOfWeek);


            List <Timeline> timelines = TimelineService.GetTimelines(this.UserId, start, end).OrderBy(timeline => timeline.TimeStamp).ToList();

            SendTimelinesWeek(timelines);
        }
Esempio n. 14
0
        public void TimelineService_GetAllPublicTimelinesWithoutContentItems_Exception_Test()
        {
            // Arrange
            Mock <ITimelineDao>    mock            = new Mock <ITimelineDao>(MockBehavior.Strict);
            Mock <IContentItemDao> contentItemMock = new Mock <IContentItemDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.FindAllPublicTimelines()).Throws(new Exception());
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            target.GetAllPublicTimelinesWithoutContentItems();
        }
Esempio n. 15
0
        public void DeleteTimeline(DateTime start, DateTime end)
        {
            int count = TimelineService.DeleteTimeline(this.UserId, start, end);

            if (count == 0)
            {
                SendUpdate("Unable to find a timelines in this range");
                return;
            }

            SendUpdate(string.Format("{0} entries have been deleted", count));
        }
Esempio n. 16
0
        public ExpensesDetailViewModel(IDatabaseService databaseService, IStorageService storageService)
        {
            var expense = databaseService.GetExpense(storageService.SelectedExpense);

            ExpenseType = expense.Type;
            Description = expense.Description;
            Location    = expense.Address;
            Amount      = expense.Cost;

            TimelineService timeline = new TimelineService();

            timeline.AddToTimeline(expense);
        }
Esempio n. 17
0
        public void TimelineService_Update_Test()
        {
            // Arrange
            Mock <ITimelineDao> mock = new Mock <ITimelineDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.Update(It.IsAny <Timeline>()));
            Mock <IContentItemDao> contentItemMock = new Mock <IContentItemDao>(MockBehavior.Strict);
            TimelineService        target          = new TimelineService(mock.Object, contentItemMock.Object);
            Timeline timeline = new Timeline();

            // Act
            target.Update(timeline);
            mock.Verify(verify => verify.Update(timeline), Times.Once);
        }
Esempio n. 18
0
        public void DeleteTimeline(int id)
        {
            Timeline timeline = TimelineService.GetTimeline(id);

            if (timeline == null)
            {
                SendUpdate("Unable to find a timeline with that id");
                return;
            }

            TimelineService.DeleteTimeline(timeline);

            SendUpdate(string.Format("Timeline entry has been deleted: {0}: \"{1}\" at {2}", timeline.Id, timeline.Label, timeline.TimeStamp));
        }
Esempio n. 19
0
 public void ExportAll()
 {
     try
     {
         var timelines = TimelineService.GetTimelines(this.UserId);
         this.ExportTimelines(this.UserName, timelines, "AllTimelines.csv");
         SendUpdate("Sent, should be in your inbox soon!");
     }
     catch (Exception ex)
     {
         SendUpdate("Sorry, I was unable to send the email.");
         WriteLog(ex, "EmailError");
     }
 }
Esempio n. 20
0
        public async Task GetJson()
        {
            string json = "{\"Test\": \"Result\"}";
            var    mock = new Mock <IWebClientHelper>();

            mock.Setup(m => m.DownloadStringAsync(It.IsAny <string>(), It.IsAny <NameValueCollection>())).Returns(TestUtils.GetCompletedTask(json));

            var    api    = new TimelineService(BaseUrl, "ABC", "123", "cache", mock.Object);
            string result = await api.GetJsonAsync("Test/Get");

            mock.Verify(m => m.DownloadStringAsync($"{BaseUrl}Test/Get", It.Is <NameValueCollection>(c => c.VerifyContains("AuthToken", "ABC"))));
            mock.Verify(m => m.DownloadStringAsync($"{BaseUrl}Test/Get", It.Is <NameValueCollection>(c => c.VerifyContains("TenantId", "123"))));
            Assert.AreEqual(json, result);
        }
Esempio n. 21
0
 public void Export(DateTime start, DateTime end)
 {
     try
     {
         var timelines = TimelineService.GetTimelines(this.UserId, start, end);
         this.ExportTimelines(this.UserName, timelines, string.Format("ExportFrom{0}To{1}.csv", start.ToString("MM-dd-yy"), end.ToString("MM-dd-yy")));
         SendUpdate("Sent, should be in your inbox soon!");
     }
     catch (Exception ex)
     {
         SendUpdate("Sorry, I was unable to send the email.");
         WriteLog(ex, "EmailError");
     }
 }
Esempio n. 22
0
 public void ExportSince(DateTime date)
 {
     try
     {
         var timelines = TimelineService.GetTimelines(this.UserId, date, DateTime.Now);
         this.ExportTimelines(this.UserName, timelines, string.Format("ExportSince{0}.csv", date.ToString("MM-dd-yy")));
         SendUpdate("Sent, should be in your inbox soon!");
     }
     catch (Exception ex)
     {
         SendUpdate("Sorry, I was unable to send the email.");
         WriteLog(ex, "EmailError");
     }
 }
Esempio n. 23
0
        public async Task PutJson500Error()
        {
            var mock = new Mock <IWebClientHelper>();

            mock.Setup(m => m.UploadStringAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(TestUtils.GetExceptionTask <string>(new WebException()));
            mock.Setup(m => m.GetStatusCode(It.IsAny <WebResponse>())).Returns(HttpStatusCode.InternalServerError);
            mock.Setup(m => m.GetResponseMessage(It.IsAny <WebResponse>())).Returns("Internal server error");

            var    api    = new TimelineService(BaseUrl, "ABC", "123", "cache", mock.Object);
            string result = await api.PutJsonAsync("Test/Put", new
            {
                Test = "Result"
            });
        }
Esempio n. 24
0
        public void Export(DateTime date)
        {
            try
            {
                DateTime start = date.AddDays((int)DayOfWeek.Sunday - (int)date.DayOfWeek);
                DateTime end   = date.AddDays((int)DayOfWeek.Saturday - (int)date.DayOfWeek);

                List <Timeline> timelines = TimelineService.GetTimelines(this.UserId, start, end).OrderBy(timeline => timeline.TimeStamp).ToList();
                this.ExportTimelines(this.UserName, timelines, string.Format("ExportWeek{0}.csv", date.ToString("MM-dd-yy")));
                SendUpdate("Sent, should be in your inbox soon!");
            }
            catch (Exception ex)
            {
                SendUpdate("Sorry, I was unable to send the email.");
                WriteLog(ex, "EmailError");
            }
        }
Esempio n. 25
0
        public async Task PutJson()
        {
            string json = "{\"Test\": \"Result\"}";
            var    mock = new Mock <IWebClientHelper>();

            mock.Setup(m => m.UploadStringAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(TestUtils.GetCompletedTask(json));

            var    api    = new TimelineService(BaseUrl, "ABC", "123", "cache", mock.Object);
            string result = await api.PutJsonAsync("Test/Put", new
            {
                Test = "Result"
            });

            mock.Verify(m => m.UploadStringAsync($"{BaseUrl}Test/Put", It.Is <string>(s => s.VerifyJson("AuthToken", "ABC"))));
            mock.Verify(m => m.UploadStringAsync($"{BaseUrl}Test/Put", It.Is <string>(s => s.VerifyJson("TenantId", "123"))));
            Assert.AreEqual(json, result);
        }
Esempio n. 26
0
        public async Task InitializeAsync()
        {
            await TestDatabase.InitializeAsync();

            Database = TestDatabase.CreateContext(_testOutputHelper);

            UserService     = new UserService(NullLogger <UserService> .Instance, Database, new PasswordService(), Clock);
            TimelineService = new TimelineService(NullLoggerFactory.Instance, Database, UserService, Clock);

            UserId = await UserService.GetUserIdByUsernameAsync("user");

            AdminId = await UserService.GetUserIdByUsernameAsync("admin");

            await OnInitializeAsync();

            OnInitialize();
        }
Esempio n. 27
0
    private IEnumerator _RemovePost()
    {
        WWW removeRequest = TimelineService.RemovePost(post);

        while (!removeRequest.isDone)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        Debug.Log("Header: " + removeRequest.responseHeaders["STATUS"]);
        Debug.Log("Text: " + removeRequest.text);
        AlertsService.removeLoadingAlert();

        if (removeRequest.responseHeaders["STATUS"] == HTML.HTTP_200)
        {
            Destroy(this.gameObject);
        }
    }
Esempio n. 28
0
        public async Task TimelineSearch_Should_Work()
        {
            await TimelineService.CreateTimelineAsync("hahaha", UserId);

            var t2 = await TimelineService.CreateTimelineAsync("bababa", UserId);

            await TimelineService.ChangePropertyAsync(t2.Id, new TimelineChangePropertyParams { Title = "hahaha" });

            await TimelineService.CreateTimelineAsync("bbbbbb", UserId);

            var searchResult = await _service.SearchTimelineAsync("hah");

            searchResult.Items.Should().HaveCount(2);
            searchResult.Items[0].Item.Name.Should().Be("hahaha");
            searchResult.Items[0].Score.Should().Be(2);
            searchResult.Items[1].Item.Name.Should().Be("bababa");
            searchResult.Items[1].Score.Should().Be(1);
        }
Esempio n. 29
0
        public async Task <ActionResult <TimelineResponse> > GetTimeline(TimelineRequest request)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            TimelineResponse response;

            if (request.Filter == null || request.Filter.isDefault)
            {
                response = await TimelineService.GetTimelineFromTimeResults(context, request);
            }
            else
            {
                response = await TimelineService.GetTimeline(context, request);
            }
            sw.Stop();
            logger.LogInformation($"Get Timeline in {sw.ElapsedMilliseconds} ms");
            return(response);
        }
Esempio n. 30
0
        public void Timeline(List <string> label, double minutes)
        {
            string input = string.Join(" ", label);

            if (!string.IsNullOrEmpty(input))
            {
                var tags = label.Where(l => l.StartsWith("#")).Select(l => l.ToUpper().Substring(1)).ToList();


                if (input.Length > MAXLABELSIZE)
                {
                    SendUpdate(string.Format("The label has been truncated to {0} characters", MAXLABELSIZE.ToString()));
                    input = input.Substring(0, 1000);
                }

                var tl = TimelineService.InsertTimeline(this.TimeUser, DateTime.Now.AddMinutes(-1 * minutes), input, tags);

                this.LastEntryDate = DateTime.Now;
                SendUpdate(string.Format("Timeline #{0} has been added.", tl.Id));
                this.RecordAway = true;
            }
        }