Пример #1
0
        public void DeleteById_IdAndCollectionWithObjToDelete_ObjectDeleted()
        {
            var objForDelete = new Player{ Id = _id};

            List<IModel> objList = new List<IModel>();
            objList.Add(objForDelete);
            objList.Add(new Player());
            objList.Add(new Player());

            IModel expected = null;

            _target.DeleteById(_id, objList);

            var actual = _target.GetById(_id, objList);

            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        public void SaveDTOobject_FileIsEmptySaveInNew()
        {
            _stubRemoteFile.Stub(x => x
              .ReadFileData(Path))
              .Return(FILE_EMPTY_LIST_STRING);

             _stubDtoPlayer = new PlayerDTO()
             {
                 Name = "",
                 Age = 0,
                 Amplua = "",
                 Height = 0,
                 Number = 0,
                 Mail = "",
                 PhoneNumber = ""
             };
             var expectedPlayersList = new List<Player>();
             _stubPlayer = new Player()
             {
                 Name = _stubDtoPlayer.Name,
                 Age = _stubDtoPlayer.Age,
                 Amplua = _stubDtoPlayer.Amplua,
                 Height = _stubDtoPlayer.Height,
                 Number = _stubDtoPlayer.Number,
                 Mail = _stubDtoPlayer.Mail,
                 PhoneNumber = _stubDtoPlayer.PhoneNumber
             };
              expectedPlayersList.Add(_stubPlayer);

             _stubSerializer.Stub(x => x
                 .Serialize(Arg<List<Player>>.Matches(actualPlayers =>
                     CheckPlayers(actualPlayers, expectedPlayersList))))
               .Return(SERIALIZEDSTRING_PLAYER_LIST);

              _target.SaveDTOobject(_stubDtoPlayer,Path);

             //In this case is same
              _stubRemoteFile.AssertWasCalled(x => x
                  .WriteFileData(Path, SERIALIZEDSTRING_PLAYER_LIST));
             //_stubRemoteFile.AssertWasCalled(x => x
             //     .WriteFileData(Arg<string>.Is.Equal(PLAYER_JSON_FILE_P_ATH),
             //     Arg<string>.Is.Equal(SERIALIZEDSTRING_PLAYER_LIST)));
        }
Пример #3
0
        public void SaveDTOobject_FileExist_AddToFile()
        {
            _stubRemoteFile.Stub(x => x
              .ReadFileData(Path))
              .Return(StringToDesirialize);

             _stubDtoPlayer = new PlayerDTO()
             {
                 Name = "",
                 Age = 0,
                 Amplua = "",
                 Height = 0,
                 Number = 0,
                 Mail = "",
                 PhoneNumber = ""
             };

             _stubPlayer = new Player()
             {
                 Name = _stubDtoPlayer.Name,
                 Age = _stubDtoPlayer.Age,
                 Amplua = _stubDtoPlayer.Amplua,
                 Height = _stubDtoPlayer.Height,
                 Number = _stubDtoPlayer.Number,
                 Mail = _stubDtoPlayer.Mail,
                 PhoneNumber = _stubDtoPlayer.PhoneNumber
             };

             _stubSerializer.Stub(x => x
                .DeSerialize<List<Player>>(StringToDesirialize))
                .Return(_playerList);

             _playerList.Add(_stubPlayer);

             _stubSerializer.Stub(x => x
                   .Serialize(Arg<List<Player>>.Matches(actualPlayers =>
                       CheckPlayers(actualPlayers, _playerList))))
                 .Return(SERIALIZEDSTRING_PLAYER_LIST);

             _target.SaveDTOobject(_stubDtoPlayer, Path);

             _stubRemoteFile.AssertWasCalled(x => x
                 .WriteFileData(Path, SERIALIZEDSTRING_PLAYER_LIST));
        }
Пример #4
0
        public void InIt()
        {
            _id = Guid.NewGuid();
            _stubModel = MockRepository.GenerateStub<IModel>();
            _stubTeamPlayers = MockRepository.GenerateStub<TeamPlayers>();
            _stubDtoPlayer = MockRepository.GenerateStub<PlayerDTO>();
            _stubPlayer = MockRepository.GenerateStub<Player>();

            _stubSerializer = MockRepository.GenerateStub<ISerializer>();
            _stubLinqService = MockRepository.GenerateStub<ILinqService>();
            _stubRemoteFile = MockRepository.GenerateStub<IRemoteFile>();
            _stubPersistentService = MockRepository.GenerateStub<IPersistentService>();
            _target = new PersistentService(_stubSerializer,
                _stubLinqService,_stubRemoteFile);
        }
Пример #5
0
        public Player DeclarePlayer(string name, int age, int number, int height, string amplua, string phonenumber, string mail)
        {
            var player = new Player()
            {
                Id = Guid.NewGuid(),
                Name = name,
                Age = age,
                Number = number,
                Height = height,
                Amplua = amplua,
                PhoneNumber = phonenumber,
                Mail = mail,
                Date = DateTime.Now
            };

            _persistentService.Saveobject(player, "player.json");

            return player;
        }
Пример #6
0
        private bool CheckPlayer(Player expected, Player actual)
        {
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Age, actual.Age);
            Assert.AreEqual(expected.Number, actual.Number);
            Assert.AreEqual(expected.Height, actual.Height);
            Assert.AreEqual(expected.Amplua, actual.Amplua);
            Assert.AreEqual(expected.PhoneNumber, actual.PhoneNumber);
            Assert.AreEqual(expected.Mail, actual.Mail);

            return true;
        }
Пример #7
0
        public void DeclarePlayer_Saveobject_Player()
        {
            var expectedPlayer = new Player()
            {
                Name = "",
                Age = 0,
                Number = 0,
                Height = 0,
                Amplua = "",
                PhoneNumber = "",
                Mail = ""
            };

            _target.DeclarePlayer(expectedPlayer.Name, expectedPlayer.Age, expectedPlayer.Number,
                expectedPlayer.Height,
                expectedPlayer.Amplua, expectedPlayer.PhoneNumber, expectedPlayer.Mail);

            _stubPersistentService.AssertWasCalled(x => x
                .Saveobject(Arg<Player>.Matches(actualPlayer => CheckPlayer(expectedPlayer, actualPlayer)),
                    Arg<string>.Is.Anything //Equal("player.json")
                ));

            //_stubPersistentService.AssertWasCalled(x => x
            //    .Saveobject(
            //        Arg<Player>.Matches(actualPlayer => actualPlayer.Age == 0 ),
            //        Arg<string>.Is.Same("player.json")
            //    ));}
        }
Пример #8
0
        public void DeclarePlayer_CheckArguments_Player()
        {
            //  ################ First Way
            var expectedPlayer = new Player()
            {
                Name = "",
                Age = 0,
                Number = 0,
                Height = 0,
                Amplua = "",
                PhoneNumber = "",
                Mail = ""
            };

            var actual = _target.DeclarePlayer(expectedPlayer.Name, expectedPlayer.Age, expectedPlayer.Number,
                expectedPlayer.Height,
                expectedPlayer.Amplua, expectedPlayer.PhoneNumber, expectedPlayer.Mail);

            Assert.AreEqual(expectedPlayer.Name, actual.Name);
            Assert.AreEqual(expectedPlayer.Age, actual.Age);
            Assert.AreEqual(expectedPlayer.Number, actual.Number);
            Assert.AreEqual(expectedPlayer.Height, actual.Height);
            Assert.AreEqual(expectedPlayer.Amplua, actual.Amplua);
            Assert.AreEqual(expectedPlayer.PhoneNumber, actual.PhoneNumber);
            Assert.AreEqual(expectedPlayer.Mail, actual.Mail);
        }
Пример #9
0
        public void GetBuId_IdAndCollectionWithSearchedId_ReturnSearchedObj()
        {
            IModel expectedobj = new Player() { Id = _id };

            var players = new List<IModel>();
            players.Add(expectedobj);
            players.Add(new Player());
            players.Add(new Player());

            var actuale = _target.GetById(_id, players);
            Assert.AreEqual(expectedobj, actuale);
        }
Пример #10
0
        public void UpdateById_IdAndEmptyCollection_ReturnNull()
        {
            List<IModel> objList = new List<IModel>();

            var objToUpdate = new Player { Id = _id };

            IModel expectedobj = null;

            _target.UpdateById(objToUpdate, objList);

            var actual = _target.GetById(_id, objList);

            Assert.AreEqual(expectedobj, actual);
        }
Пример #11
0
        public void UpdateById_IdAndCollectionWithObjToUpdate_ObjectUpdated()
        {
            var expectedObjName = "object updated";

            var objForUpdate = new Player {Id = _id,Name = "first obj"};
            List<IModel> objList = new List<IModel>();
            objList.Add(objForUpdate);
            objList.Add(new Player());
            objList.Add(new Player());

            var objToUpdate = new Player{Id = _id,Name = expectedObjName};

            _target.UpdateById(objToUpdate, objList);

            var actual = (_target.GetById(_id, objList) as Player).Name;

            Assert.AreEqual(expectedObjName,actual);
        }
Пример #12
0
        public void UpdateById_CollectionWitoutSearchedId_ReturnNull()
        {
            List<IModel> objList = new List<IModel>();
            objList.Add(new Player());
            objList.Add(new Player());
            objList.Add(new Player());

            var objToUpdate = new Player { Id = _id };

            IModel expectedobj = null;

            _target.UpdateById(objToUpdate, objList);

            var actual = _target.GetById(_id, objList);

            Assert.AreEqual(expectedobj, actual);
        }
Пример #13
0
        public void Save_ObjToSaveAndCollection_ObjectSaved()
        {
            var objForSave = new Player { Id = _id };

            List<IModel> objList = new List<IModel>();
            objList.Add(new Player());
            objList.Add(new Player());

            IModel expected = objForSave;

            _target.Save(objForSave,objList);

            var actual = _target.GetById(_id, objList);

            Assert.AreEqual(expected, actual);
        }