Esempio n. 1
0
        public void GetEntityByIdsWithSeveralValOK()
        {
            var         projectId = Guid.NewGuid();
            List <Note> notes     = NoteUtility.GetFakeSimpleNotes();

            string content = JsonConvert.SerializeObject(notes, new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            });

            Mock <HttpWebRequest> mockWebRequest = FakeWebRequest.CreateRequestWithResponse(content);

            mockWebRequest.SetupSet(r => r.Method = "GET").Verifiable();

            Guid[]      ids         = notes.Select((n => n.Id)).ToArray();
            List <Note> resultNotes = request.GetEntityByIds <Note>(ids, projectId).GetAwaiter().GetResult();

            string filter = Filter.In("Id", ids).ToString();


            string expectedUrl = AproplanApiUtility.BuildRestUrl(request.ApiRootUrl, "notes", request.ApiVersion, request.RequesterId, request.TokenInfo.Token);

            expectedUrl += "&filter=" + AproplanApiUtility.EncodeUrl(filter) + "&projectid=" + projectId;

            Assert.AreEqual(expectedUrl, FakeWebRequest.Instance.UriCalled[0].ToString());

            Assert.AreEqual(notes.Count, resultNotes.Count);
            for (int i = 0; i < notes.Count; i++)
            {
                var expectedNote = notes[i];
                Assert.AreEqual(expectedNote.Id, resultNotes[i].Id);
            }

            mockWebRequest.Verify();
        }
        //在目前位置增加一個音符
        public void onAddNote()
        {
            if (editor.brush.currentBrush == NoteType.Null)
            {
                print(editor.brush.currentBrush.ToString());
                return;
            }

            Note note = NoteUtility.GenerateNote(editor.brush.currentBrush);

            var length = (int)editor.trackMapEditor.noteLength.Value;
            var offset = editor.trackMapEditor.noteOffset.Value;
            var angle  = editor.trackMapEditor.noteAngle.Value;

            if (editor.getCurrentNote != null)
            {
                note.position = length + editor.getCurrentNoteGridPosition;
            }
            else
            {
                note.position = editor.getCurrentNoteGridPosition;
            }

            note.lenght  = length;
            note.Xoffset = offset;
            note.angle   = angle;

            editor.getTrackMap.Notes.Add(note);

            editor.getTrackMap.Sort();

            editor.getCurrentNoteIndex = editor.getTrackMap.Notes.IndexOf(note);
        }
Esempio n. 3
0
        public void GetEntityByIdOK()
        {
            var  projectId = Guid.NewGuid();
            Note note      = NoteUtility.GetFakeSimpleNotes()[0];

            string content = JsonConvert.SerializeObject(new List <Note> {
                note
            }, new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            });

            Mock <HttpWebRequest> mockWebRequest = FakeWebRequest.CreateRequestWithResponse(content);

            mockWebRequest.SetupSet(r => r.Method = "GET").Verifiable();

            Note resultNote = request.GetEntityById <Note>(note.Id, projectId).GetAwaiter().GetResult();

            string filter = string.Format("Filter.Eq(Id,{0})", note.Id);


            string expectedUrl = AproplanApiUtility.BuildRestUrl(request.ApiRootUrl, "notes", request.ApiVersion, request.RequesterId, request.TokenInfo.Token);

            expectedUrl += "&filter=" + AproplanApiUtility.EncodeUrl(filter) + "&projectid=" + projectId;

            Assert.AreEqual(expectedUrl, FakeWebRequest.Instance.UriCalled[0].ToString());

            Assert.AreEqual(note.Id, resultNote.Id);

            mockWebRequest.Verify();
        }
        public void SyncNotesOK()
        {
            Guid        projectId = Guid.NewGuid();
            List <Note> fakeNotes = NoteUtility.GetFakeSimpleNotes();

            string content = JsonConvert.SerializeObject(fakeNotes.GetRange(0, 2), new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            });

            Mock <HttpWebRequest> mockWebRequest = FakeWebRequest.CreateRequestWithResponse(content, new Dictionary <string, string> {
                { "SyncTimestamp", "stamp1;noteid=3" }
            });

            mockWebRequest.SetupSet(r => r.Method = "GET").Verifiable();

            SyncResult <Note> result = syncService.SyncNotes(projectId, null).GetAwaiter().GetResult();


            string expectedUrl = AproplanApiUtility.BuildRestUrl(mockApi.Object.ApiRootUrl, "notesync", mockApi.Object.ApiVersion, mockApi.Object.RequesterId);

            expectedUrl += "&projectid=" + projectId;
            Assert.AreEqual(expectedUrl, FakeWebRequest.Instance.UriCalled[0].ToString());
            Assert.AreEqual(2, result.Data.Count);
            Assert.AreEqual(fakeNotes[0].Id, result.Data[0].Id);
            Assert.AreEqual(fakeNotes[1].Id, result.Data[1].Id);
            Assert.AreEqual("stamp1;noteid=3", result.ContinuationToken);
            mockWebRequest.Verify();
        }
        //在目前位置插入一個音符,之後的音符會位移這個音符的長度
        public void onInsertNote()
        {
            if (editor.brush.currentBrush == NoteType.Null)
            {
                print(editor.brush.currentBrush.ToString());
                return;
            }


            Note note = NoteUtility.GenerateNote(editor.brush.currentBrush);

            var length = (int)editor.trackMapEditor.noteLength.Value;
            var offset = editor.trackMapEditor.noteOffset.Value;
            var angle  = editor.trackMapEditor.noteAngle.Value;

            note.position = editor.getCurrentNoteGridPosition;

            note.lenght  = length;
            note.Xoffset = offset;
            note.angle   = angle;

            editor.getTrackMap.Notes.Add(note);

            editor.getCurrentNoteIndex = editor.getTrackMap.Notes.IndexOf(note);

            for (int i = 0; i < editor.getTrackMap.Notes.Count; i++)
            {
                if (editor.getTrackMap.Notes[i] == note ||
                    editor.getTrackMap.Notes[i].position < note.position)
                {
                    continue;
                }

                editor.getTrackMap.Notes[i].position += note.lenght;
            }

            editor.getTrackMap.Sort();

            editor.getCurrentNoteIndex = editor.getTrackMap.Notes.IndexOf(note);
        }
Esempio n. 6
0
        public void GetEntityByIdsWithQueryParamsOK()
        {
            var  projectId = Guid.NewGuid();
            Note note      = NoteUtility.GetFakeSimpleNotes()[0];

            string content = JsonConvert.SerializeObject(new List <Note> {
                note
            }, new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            });

            Mock <HttpWebRequest> mockWebRequest = FakeWebRequest.CreateRequestWithResponse(content);

            mockWebRequest.SetupSet(r => r.Method = "GET").Verifiable();

            Guid[]      ids         = new Guid[] { note.Id };
            List <Note> resultNotes = request.GetEntityByIds <Note>(ids, projectId, null, new Dictionary <string, string> {
                { "testparam", "john" }
            }).GetAwaiter().GetResult();

            string filter = Filter.Eq("Id", note.Id).ToString();


            string expectedUrl = AproplanApiUtility.BuildRestUrl(request.ApiRootUrl, "notes", request.ApiVersion, request.RequesterId, request.TokenInfo.Token);

            expectedUrl += "&filter=" + AproplanApiUtility.EncodeUrl(filter) + "&projectid=" + projectId + "&testparam=john";

            Assert.AreEqual(expectedUrl, FakeWebRequest.Instance.UriCalled[0].ToString());

            Assert.AreEqual(1, resultNotes.Count);
            Assert.AreEqual(note.Id, resultNotes[0].Id);


            mockWebRequest.Verify();
        }
        public void SyncAllNotesCancelledOK()
        {
            Guid        projectId      = Guid.NewGuid();
            List <Note> fakeNotes      = NoteUtility.GetFakeSimpleNotes();
            int         index          = 0;
            List <Note> resultToReturn = fakeNotes.GetRange(index, 2);
            string      content        = JsonConvert.SerializeObject(resultToReturn, new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            });

            string stamp = "stamp" + index + ";noteid=" + index;
            Mock <HttpWebRequest> mockWebRequest = FakeWebRequest.CreateRequestWithResponse(content, new Dictionary <string, string> {
                { "SyncTimestamp", stamp }
            });

            mockWebRequest.SetupSet(r => r.Method = "GET").Verifiable();

            string lastStamp = stamp;
            string baseUrl   = AproplanApiUtility.BuildRestUrl(mockApi.Object.ApiRootUrl, "notesync", mockApi.Object.ApiVersion, mockApi.Object.RequesterId);

            baseUrl += "&projectid=" + projectId;
            SyncResult <Note> result = syncService.SyncAllNotes(projectId, null, (SyncResult <Note> r, ref bool cancel) => {
                string expectedUrl = baseUrl;
                if (index > 0)
                {
                    expectedUrl = baseUrl + "&timestamp=" + Uri.EscapeDataString(lastStamp);
                }
                Assert.AreEqual(expectedUrl, FakeWebRequest.Instance.UriCalled[FakeWebRequest.Instance.UriCalled.Count - 1].ToString());
                Assert.AreEqual(stamp, r.ContinuationToken);
                Assert.AreEqual(resultToReturn.Count, r.Data.Count);
                for (var i = 0; i < resultToReturn.Count; i++)
                {
                    Assert.AreEqual(resultToReturn[i].Id, r.Data[i].Id);
                }

                lastStamp = stamp;
                index    += 2;
                int cpt   = fakeNotes.Count - index;

                resultToReturn = cpt > 0 ? fakeNotes.GetRange(index, cpt < 2 ? 1 : 2) : new List <Note>();
                content        = JsonConvert.SerializeObject(resultToReturn, new JsonSerializerSettings
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc
                });
                if (resultToReturn.Count > 0)
                {
                    stamp = "stamp" + index + ";noteid=" + index;
                }
                else
                {
                    stamp = null;
                }
                mockWebRequest = FakeWebRequest.CreateRequestWithResponse(content, new Dictionary <string, string> {
                    { "SyncTimestamp", stamp }
                });

                cancel = true;
            }).GetAwaiter().GetResult();



            Assert.AreEqual(1, FakeWebRequest.Instance.UriCalled.Count);
            Assert.AreEqual(2, result.Data.Count);

            Assert.AreEqual(lastStamp, result.ContinuationToken);

            mockWebRequest.Verify();
        }