private void setFieldsFromGuid(Guid guid, TeamPicture teamPicture)
 {
     teamPicture.Message = guid.ToString();
     teamPicture.Picture = guid.ToByteArray();
     teamPicture.PictureHeight = HEIGHT;
     teamPicture.PictureWidth = WIDTH;
 }
        public void Assure_webservice_can_save_and_retreive_teampicture()
        {
            var webservice = new TeamPictureService.TeamPictureRepositoryWebserviceClient();
            var alreadySavedCount = webservice.Get(new CurrentTeamPictureSpecification()).Count();

            TeamPicture teamPicture = new TeamPicture();
            var guid = Guid.NewGuid();
            teamPicture.Message = guid.ToString();
            teamPicture.Picture = guid.ToByteArray();
            teamPicture.PictureHeight = 480;
            teamPicture.PictureWidth = 640;

            webservice.Save(new [] {teamPicture});

            var returnedTeamPictures = webservice.Get(new CurrentTeamPictureSpecification());

            returnedTeamPictures.Count().ShouldBe(1);
            TeamPicture returnedTeamPicture = returnedTeamPictures.Last();

            returnedTeamPicture.Message.ShouldBe(teamPicture.Message);

            for (int i = 0; i < teamPicture.Picture.Length; i++)
            {
                Assert.AreEqual(teamPicture.Picture[i], returnedTeamPicture.Picture[i]);
            }

            returnedTeamPicture.Picture.ShouldBe(teamPicture.Picture);
            returnedTeamPicture.PictureHeight.ShouldBe(480);
            returnedTeamPicture.PictureWidth.ShouldBe(640);
        }
 private void Assert_single_result(IEnumerable<TeamPicture> teamPictures, TeamPicture testData)
 {
     teamPictures.Count().ShouldBe(1);
     teamPictures.First().Message.ShouldBe(testData.Message);
     teamPictures.First().Picture.ShouldBe(testData.Picture);
     teamPictures.First().PictureHeight.ShouldBe(HEIGHT);
     teamPictures.First().PictureWidth.ShouldBe(WIDTH);
 }
 public void Setup()
 {
     DeleteDatabaseIfExists();
     RecreateSessionFactory();
     this.dbRepo = new TeamPictureDatabaseRepository(sessionFactory);
     
     firstTeamPicture = new TeamPicture();
     _firstGuid = Guid.NewGuid();
     setFieldsFromGuid(_firstGuid, firstTeamPicture);
 }
        public void Assure_old_picture_is_overwritten_when_new_is_saved()
        {
            var secondGuid = Guid.NewGuid();
            var secondTeamPicture = new TeamPicture();
            setFieldsFromGuid(secondGuid, secondTeamPicture);

            dbRepo.Save(firstTeamPicture);
            dbRepo.Save(secondTeamPicture);

            RecreateSessionFactory();
            var newDbRepo = new TeamPictureDatabaseRepository(sessionFactory);

            var teamPictures = newDbRepo.Get(new CurrentTeamPictureSpecification());

            Assert_single_result(teamPictures, secondTeamPicture);
        }
        public void Assure_webservice_can_handle_large_messages()
        {
            var webservice = new TeamPictureService.TeamPictureRepositoryWebserviceClient();
            var alreadySavedCount = webservice.Get(new CurrentTeamPictureSpecification()).Count();

            TeamPicture teamPicture = new TeamPicture();
            var guid = Guid.NewGuid();
            teamPicture.Message = guid.ToString();
            teamPicture.Picture = new byte[OneMegaByte];
            teamPicture.PictureHeight = 480;
            teamPicture.PictureWidth = 640;

            webservice.Save(new[] { teamPicture });

            var returnedTeamPictures = webservice.Get(new CurrentTeamPictureSpecification());

            returnedTeamPictures.Count().ShouldBe(1);
            returnedTeamPictures.Last().Message.ShouldBe(teamPicture.Message);
            returnedTeamPictures.Last().Picture.Length.ShouldBe(OneMegaByte);
            returnedTeamPictures.Last().PictureHeight.ShouldBe(480);
            returnedTeamPictures.Last().PictureWidth.ShouldBe(640);
        }