public void Map_EnumQuestion_Correct()
        {
            //Arrange
            var question = new Question {
                Id       = 11,
                DataType = QuestionDataType.Enum,
                Value    = "1"
            };

            var model = new ChangeNoteViewModel {
                ChangeReason  = "Hi",
                NewValue      = "2",
                OriginalValue = "1",
                QuestionId    = 11
            };

            //Act
            ChangeNote result = builder.CreateChangeNote(question, model.OriginalValue, model.NewValue, model.ChangeReason);

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Question, Is.EqualTo(question));
            Assert.That(result.ChangeDate.Date, Is.EqualTo(DateTime.UtcNow.Date));
            Assert.That(result.ChangeReason, Is.EqualTo(model.ChangeReason));
            Assert.That(result.OriginalValue, Is.EqualTo("1"));
            Assert.That(result.NewValue, Is.EqualTo("2"));
        }
예제 #2
0
 void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
 {
     newValue = new List <demo.Bean1>();
     foreach (var e in ((demo.Module1.Value)value).List9)
     {
         newValue.Add(e.Copy());
     }
 }
예제 #3
0
            void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
            {
                ChangeNoteSet <int> noteset = (ChangeNoteSet <int>)note;

                foreach (var a in noteset.Added)
                {
                    newValue.Add(a);
                }
                foreach (var r in noteset.Removed)
                {
                    newValue.Remove(r);
                }
            }
예제 #4
0
            void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
            {
                ChangeNoteMap1 <long, long> notemap1 = (ChangeNoteMap1 <long, long>)note;

                foreach (var a in notemap1.Replaced)
                {
                    newValue[a.Key] = a.Value;
                }
                foreach (var r in notemap1.Removed)
                {
                    newValue.Remove(r);
                }
            }
예제 #5
0
            void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
            {
                ChangeNoteMap2 <long, demo.Module2.Value> notemap2 = (ChangeNoteMap2 <long, demo.Module2.Value>)note;

                notemap2.MergeChangedToReplaced(((demo.Module1.Value)value).Map11);

                foreach (var a in notemap2.Replaced)
                {
                    newValue[a.Key] = a.Value;
                }
                foreach (var r in notemap2.Removed)
                {
                    newValue.Remove(r);
                }
            }
예제 #6
0
파일: ModuleBag.cs 프로젝트: e2wugui/zeze
            void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
            {
                // 增量变化,通知变更。
                ChangeNoteMap2 <int, BItem> notemap2 = (ChangeNoteMap2 <int, BItem>)note;
                BBag bbag = (BBag)value;

                notemap2.MergeChangedToReplaced(bbag.Items);

                SChanged changed = new SChanged();

                changed.Argument.ChangeTag = BChangedResult.ChangeTagNormalChanged;

                changed.Argument.ItemsReplace.AddRange(notemap2.Replaced);
                foreach (var p in notemap2.Removed)
                {
                    changed.Argument.ItemsRemove.Add(p);
                }

                Game.App.Instance.Game_Login.Onlines.SendReliableNotify((long)key, Name, changed);
            }
예제 #7
0
파일: ModuleBuf.cs 프로젝트: e2wugui/zeze
            void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
            {
                // 增量变化,通知变更。
                ChangeNoteMap2 <int, BBuf> notemap2 = (ChangeNoteMap2 <int, BBuf>)note;
                BBufs record = (BBufs)value;

                notemap2.MergeChangedToReplaced(record.Bufs);

                SChanged changed = new SChanged();

                changed.Argument.ChangeTag = BBufChanged.ChangeTagNormalChanged;

                changed.Argument.Replace.AddRange(notemap2.Replaced);
                foreach (var p in notemap2.Removed)
                {
                    changed.Argument.Remove.Add(p);
                }

                Game.App.Instance.Game_Login.Onlines.Send((long)key, changed);
            }
예제 #8
0
파일: ModuleEquip.cs 프로젝트: e2wugui/zeze
            void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
            {
                // 增量变化,通知变更。
                ChangeNoteMap2 <int, Game.Bag.BItem> notemap2 = (ChangeNoteMap2 <int, Game.Bag.BItem>)note;
                BEquips bequips = (BEquips)value;

                notemap2.MergeChangedToReplaced(bequips.Items);

                SEquipement changed = new SEquipement();

                changed.Argument.ChangeTag = Game.Bag.BChangedResult.ChangeTagNormalChanged;

                changed.Argument.ItemsReplace.AddRange(notemap2.Replaced);
                foreach (var p in notemap2.Removed)
                {
                    changed.Argument.ItemsRemove.Add(p);
                }

                Game.App.Instance.Game_Login.Onlines.Send((long)key, changed);
            }
        public void MappingTest()
        {
            //Arrange
            var dataStorage = new Mock <IDataStorage>();
            var entity      = new ChangeNote {
                Id            = 1,
                ChangeDate    = DateTime.Today.AddDays(-10),
                ChangeReason  = "Calculation error",
                NewValue      = "2",
                OriginalValue = "3",
                Question      = new Question {
                    Id = 4, Value = "2"
                }
            };
            var updatedEntity = new ChangeNote()
            {
                Id            = 1,
                ChangeDate    = DateTime.Today.AddDays(1),
                ChangeReason  = "Typo",
                NewValue      = "7",
                OriginalValue = "2",
                Question      = new Question {
                    Id = 4, Value = "7"
                }
            };
            var repository = new ChangeNoteRepository(dataStorage.Object);

            dataStorage.Setup(ds => ds.GetData <ChangeNote>()).Returns(new List <ChangeNote> {
                entity
            });
            //Act
            repository.Edit(updatedEntity);
            //Assert
            //Values are equal
            Assert.That(entity.ChangeDate, Is.EqualTo(updatedEntity.ChangeDate));
            Assert.That(entity.ChangeReason, Is.EqualTo(updatedEntity.ChangeReason));
            Assert.That(entity.OriginalValue, Is.EqualTo(updatedEntity.OriginalValue));
            Assert.That(entity.NewValue, Is.EqualTo(updatedEntity.NewValue));
        }
        public void Map_EnumQuestion_Incorrect()
        {
            //Arrange
            var question = new Question {
                Id       = 11,
                DataType = QuestionDataType.Enum,
                Value    = "1"
            };

            var model = new ChangeNoteViewModel {
                ChangeReason  = "Hi",
                NewValue      = "This is incorrect enum string",
                OriginalValue = "1",
                QuestionId    = 11
            };

            //Act
            ChangeNote result = builder.CreateChangeNote(question, model.OriginalValue, model.NewValue, model.ChangeReason);

            //Assert
            Assert.That(result, Is.Null);
        }
        public void Map_NumberQuestion_Incorrect()
        {
            //Arrange
            var question = new Question {
                Id       = 11,
                DataType = QuestionDataType.Number,
                Value    = 3.5m.ToString(CultureInfo.InvariantCulture)
            };

            var model = new ChangeNoteViewModel {
                ChangeReason  = "Hi",
                NewValue      = "This is incorrect number string",
                OriginalValue = 3.5m.ToString(CultureInfo.InvariantCulture),
                QuestionId    = 11
            };

            //Act
            ChangeNote result = builder.CreateChangeNote(question, model.OriginalValue, model.NewValue, model.ChangeReason);

            //Assert
            Assert.That(result, Is.Null);
        }
예제 #12
0
파일: ModuleBag.cs 프로젝트: e2wugui/zeze
 public void OnChanged(object key, Bean value, ChangeNote note)
 {
     // 整个记录改变没有 note,只有Map,Set才有note。
     OnChanged(key, value);
 }
        public ChangeNote CreateChangeNote(Question question, string originalValue, string newValue, string changeReason)
        {
            var changeNote = new ChangeNote {
                Question     = question,
                ChangeReason = changeReason,
                ChangeDate   = DateTime.UtcNow
            };

            switch (question.DataType)
            {
            case QuestionDataType.Date:
            case QuestionDataType.Time:
                DateTime newDate;
                if (
                    !DateTime.TryParse(newValue, CultureInfo.InvariantCulture,
                                       DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out newDate))
                {
                    return(null);
                }
                DateTime originalDate;
                if (
                    !DateTime.TryParse(originalValue, CultureInfo.InvariantCulture,
                                       DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out originalDate))
                {
                    return(null);
                }

                changeNote.NewValue      = newDate.ToString(CultureInfo.InvariantCulture);
                changeNote.OriginalValue = originalDate.ToString(CultureInfo.InvariantCulture);
                break;

            case QuestionDataType.String:
                changeNote.NewValue      = newValue;
                changeNote.OriginalValue = originalValue;
                break;

            case QuestionDataType.Integer:
            case QuestionDataType.Enum:
                int newInt;
                if (!int.TryParse(newValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out newInt))
                {
                    return(null);
                }
                int originalInt;
                if (!int.TryParse(originalValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out originalInt))
                {
                    return(null);
                }

                changeNote.NewValue      = newInt.ToString(CultureInfo.InvariantCulture);
                changeNote.OriginalValue = originalInt.ToString(CultureInfo.InvariantCulture);
                break;

            case QuestionDataType.Number:
                decimal newNumber;
                if (!decimal.TryParse(newValue, NumberStyles.Number, CultureInfo.InvariantCulture, out newNumber))
                {
                    return(null);
                }
                decimal originalNumber;
                if (!decimal.TryParse(originalValue, NumberStyles.Number, CultureInfo.InvariantCulture, out originalNumber))
                {
                    return(null);
                }

                changeNote.NewValue      = newNumber.ToString(CultureInfo.InvariantCulture);
                changeNote.OriginalValue = originalNumber.ToString(CultureInfo.InvariantCulture);
                break;
            }
            changeNoteRepository.Add(changeNote);
            changeNoteRepository.Save();

            question.ChangeNotes.Add(changeNote);

            return(changeNote);
        }
예제 #14
0
 void ChangeListener.OnChanged(object key, Bean value, ChangeNote note)
 {
     newValue = ((demo.Module1.Value)value).Int1;
 }