예제 #1
0
        public void Connection_PushVersion_Parameter_ChangesNull()
        {
            User dummy = new User() { Name = "Crash Test Dummy", Password = "******" };
            int versionNumber = 1;

            PieServiceClient pieService = new PieServiceClient();

            pieService.Connect(dummy);

            string[] changes = null;

            try
            {
                pieService.PushVersion("", versionNumber, changes, dummy);
                Assert.Fail("Possible to submit changes when null");
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("Value cannot be null"))
                    Assert.Fail(e.Message);
            }
        }
예제 #2
0
        public void Connection_PushVersion_Parameter_UserPasswordNull()
        {
            User dummy = new User() { Name = "Crash Test Dummy", Password = "******" };
            int versionNumber = 1;

            PieServiceClient pieService = new PieServiceClient();

            pieService.Connect(dummy);

            string[] changes = new string[]{AbstractChange.ItemCreationMark + "SomeFileName.txt",
                                            AbstractChange.BlockSeparatorMark,
                                            AbstractChange.LineInsertionMark + "0" + AbstractChange.LineInsertionMark + "This is inserted",
                                            AbstractChange.BlockSeparatorMark};

            dummy.Password = null;

            try
            {
                pieService.PushVersion("", versionNumber, changes, dummy);
                Assert.Fail("Possible to submit changes when user's password is null");
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("User's password is invalid"))
                    Assert.Fail(e.Message);
            }
        }
        /// <summary>
        /// Pushes the current changes to the server and handles any resulting conflicts.
        /// </summary>
        /// <returns>A number of conflicts received from the server that the caller should handle.</returns>
        private IList<Conflict> PushToServer()
        {
            //try
            //{
                using (
                    var pieService = new PieServiceClient())
                {
                    IList<Conflict> conflicts = new List<Conflict>();
                    var dummyUser = new User()
                        {
                            Name = "Morten",
                            Password = "******"
                        };

                    // First fetch the version number of the server and compare to the current
                    var versionNumber = UpdateClient(pieService, ref conflicts);

                    // Push the current version to the server
                    var versionPath = FileSystem.VERSION_DIR + GetCurrentVersion() + VersionExtension;
                    var version = ReadAllLines(versionPath);
                    var result = pieService.PushVersion(Root, versionNumber, version, dummyUser);

                    // If there are no conflicts, the current changes have been pushed and we can store the version locally and erase them from the current version
                    if (result.Any() == false)
                    {
                        FileSystemAdaptee.WriteAllLines(FileSystem.VERSION_DIR + versionNumber + VersionExtension, version);
                        FileSystemAdaptee.Delete(versionPath);
                        return conflicts;
                    }

                    // Instantiate all the conflicts
                    foreach (string[] t in result)
                    {
                        String[] oldFileContent = new string[t.Length - 1];
                        for (int j = 1; j < t.Length; j++)
                        {
                            oldFileContent[j - 1] = t[j];
                        }
                        conflicts.Add(new Conflict(t[0], oldFileContent, ReadAllLines(t[0])));
                    }

                    // Return the conflicts
                    return conflicts;
                }
            //}
            //catch (Exception)
            //{
                // If we hit an exception when pushing to server we simply ignore it
                // and avoid incrementing the version - the changes will be pushed once
                // the server is back on track
                return new List<Conflict>();
            //}
        }