public virtual void Create(Meeting meeting)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         using (var command = new SqlCommand("[dbo].[createMeeting]", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@Id", meeting.Id);
             command.Parameters.AddWithValue("@Title", meeting.Title);
             command.Parameters.AddWithValue("@OwnerId", meeting.Owner.Id);
             command.Parameters.AddWithValue("@PlaceId", meeting.Place.Id);
             var returnValue = command.Parameters.Add("@Return", SqlDbType.Int);
             returnValue.Direction = ParameterDirection.ReturnValue;
             using (new LogWrapper("Adding meeting in database"))
             {
                 command.ExecuteNonQuery();
             }
             if ((int)returnValue.Value == Sqlerror)
             {
                 _logger.Warn("Attempt to create meeting with existing data");
                 throw new ArgumentException("Meeting with this data alredy exists");
             }
         }
     }
 }
        public void Test_AddAndGetMembers()
        {
            //arrange
            var meetingRepository = new MeetingsRepository(
                _connectionString,
                new UsersRepository(_connectionString),
                new PlacesRepository(_connectionString)
                );

            var user1 = TestHelper.GenerateTestUser();
            var user2 = TestHelper.GenerateTestUser();
            var owner = TestHelper.GenerateTestUser();
            meetingRepository.UsersRepository.Create(user1);
            meetingRepository.UsersRepository.Create(user2);
            meetingRepository.UsersRepository.Create(owner);

            var place = TestHelper.GenerateTestPlace();
            meetingRepository.PlacesRepository.Create(place);

            var meeting = new Meeting
            {
                Id = Guid.NewGuid(),
                Title = "title",
                Place = place,
                Owner = owner
            };
            meetingRepository.Create(meeting);
            //act
            meetingRepository.AddMember(meeting.Id, user1.Id);
            meetingRepository.AddMember(meeting.Id, user2.Id);
            var members = meetingRepository.GetMembers(meeting.Id);
            //asserts
            Assert.IsTrue(members.Count() == 3);
        }
Beispiel #3
0
 public static Meeting GenerateTestMeeting(Guid id)
 {
     var meeting = new Meeting
     {
         Id = id,
         Owner = GenerateTestUser(Guid.NewGuid()),
         Place = GenerateTestPlace(Guid.NewGuid()),
         Title = "Test meeting title " + _count++
     };
     return meeting;
 }
 public static void AddMeeting(Meeting meeting)
 {
     using (var client = new HttpClient { BaseAddress = new Uri("http://localhost:25889/") })
     {
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var response = client.PostAsJsonAsync("api/meetings", meeting).Result;
         if (response.IsSuccessStatusCode)
         {
             MessageBox.Show("Meeting Added");
         }
         else
         {
             MessageBox.Show("Error Code" +
                             response.StatusCode + " : Message - " + response.ReasonPhrase);
         }
     }
 }
 public void Update(Meeting updateMeet)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         using (var command = new SqlCommand("[dbo].[updateMeeting]", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@Id", updateMeet.Id);
             command.Parameters.AddWithValue("@PlaceId", updateMeet.Place.Id);
             command.Parameters.AddWithValue("@Title", updateMeet.Title);
             var returnValue = command.Parameters.Add("@Return", SqlDbType.Int);
             returnValue.Direction = ParameterDirection.ReturnValue;
             using (new LogWrapper("Updating meeting in database"))
             {
                 command.ExecuteNonQuery();
             }
             if ((int)returnValue.Value == Sqlerror)
             {
                 _logger.Warn("Attempt to update not existing meeting");
                 throw new ArgumentException("Meeting not found");
             }
         }
     }
 }
 public IEnumerable<Meeting> GetAllMeetings()
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         using (var command = new SqlCommand("[dbo].[getAllMeetings]", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             using (new LogWrapper("Getting all meetings from database"))
             {
                 using (var reader = command.ExecuteReader())
                 {
                     while (reader.Read())
                     {
                         var ownerId = reader.GetGuid(reader.GetOrdinal("OwnerId"));
                         var placeId = reader.GetGuid(reader.GetOrdinal("PlaceId"));
                         var meeting = new Meeting
                         {
                             Id = reader.GetGuid(reader.GetOrdinal("Id")),
                             Owner = UsersRepository.Get(ownerId),
                             Place = PlacesRepository.Get(placeId),
                             Title = reader.GetString(reader.GetOrdinal("Title")),
                             Participents = GetMembers(reader.GetGuid(reader.GetOrdinal("Id")))
                         };
                         yield return meeting;
                     }
                 }
             }
         }
     }
 }
 //Проверяет, нужно ли вызывать MeetingsHttpClient.UpdateMeeting(Meeting meeting)
 public void ProveThanUpdateMeeting()
 {
     //Проверка на заполненность SelectedMeeting
     if (SelectedMeeting.Title == null)
         return;
     //Проверка на изменения
     if (UpdatedPlaceId.Equals(SelectedMeeting.Place.Id) &&
         UpdatedTitle.Equals(SelectedMeeting.Title))
     {
         MessageBox.Show("Nothing to update");
         return;
     }
     var meeting = new Meeting()
     {
         Id = SelectedMeeting.Id,
         Owner = SelectedMeeting.Owner,
         Place = PlacesHttpClient.GetPlaceById(UpdatedPlaceId),
         Title = UpdatedTitle
     };
     MeetingsHttpClient.UpdateMeeting(meeting);
 }
        public void Initialize()
        {
            Meetings = MeetingsHttpClient.GetAllMeetings();

            var allUsers = UsersHttpClient.GetAllUsers();
            UsersIdCollection = new ObservableCollection<Guid>();
            foreach (var user in allUsers)
            {
                UsersIdCollection.Add(user.Id); //Заполняем коллекцию идентификаторов всех пользователей (для ComboBox)
            }

            var allPlaces = PlacesHttpClient.GetAllPlaces();
            PlacesIdCollection = new ObservableCollection<Guid>();
            foreach (var place in allPlaces)
            {
                PlacesIdCollection.Add(place.Id);//Заполняем коллекцию идентификаторов всех мест (для ComboBox)
            }

            SelectedMeeting = new Meeting();
        }
 //Составление встречи из данных формы и добавление ее в БД
 public void CompositThanAddMeeting()
 {
     var place = PlacesHttpClient.GetPlaceById(NewMeetingPlaceId);
     var owner = UsersHttpClient.GetUserById(NewMeetingOwnerId);
     var meeting = new Meeting()
     {
         Owner = owner,
         Place = place,
         Title = NewMeetingTitle
     };
     MeetingsHttpClient.AddMeeting(meeting);
 }
 public void Create(Meeting meeting)
 {
     if (!_usersRepository.Contains(meeting.Owner.Id))
         throw new Exception(string.Format("Пользователь {0} не найден", meeting.Owner.Id));
     //код создания встречи
 }
        public void Test_CreateAndGetMeet()
        {
            //arrange
            var usersRepository = new Mock<UsersRepository>(_connectionString) { CallBase = true };
            usersRepository.Setup(t => t.Get(It.IsAny<Guid>())).Returns(new User());

            var placesRepository = new Mock<PlacesRepository>(_connectionString) { CallBase = true };
            placesRepository.Setup(t => t.Get(It.IsAny<Guid>())).Returns(new Place());

            var meetingRepository = new MeetingsRepository(
                _connectionString,
                usersRepository.Object,
                placesRepository.Object
                );

            var user = TestHelper.GenerateTestUser();
            meetingRepository.UsersRepository.Create(user);
            var place = TestHelper.GenerateTestPlace();
            meetingRepository.PlacesRepository.Create(place);
            var meeting = new Meeting
            {
                Id = Guid.NewGuid(),
                Owner = user,
                Place = place,
                Title = "titlemeet"
            };

            //act
            meetingRepository.Create(meeting);
            var resultMeet = meetingRepository.Get(meeting.Id);

            //asserts
            Assert.IsTrue(meeting.Title == resultMeet.Title);
        }
        public void Test_UpdateMeeting()
        {
            //arrange
            var meetingRepository = new MeetingsRepository(
                _connectionString,
                new UsersRepository(_connectionString),
                new PlacesRepository(_connectionString)
                );

            var user = TestHelper.GenerateTestUser(Guid.NewGuid());
            meetingRepository.UsersRepository.Create(user);

            var place = TestHelper.GenerateTestPlace(Guid.NewGuid());
            meetingRepository.PlacesRepository.Create(place);

            var meeting = new Meeting
            {
                Id = Guid.NewGuid(),
                Owner = user,
                Place = place,
                Title = "titlemeet"
            };
            var updMeeting = new Meeting
            {
                Id = meeting.Id,
                Owner = user,
                Place = place,
                Title = "newtitlemeet"
            };
            //act
            meetingRepository.Create(meeting);
            meetingRepository.Update(updMeeting);
            //asserts
            Assert.IsTrue(updMeeting.Owner.Id.Equals(meetingRepository.Get(meeting.Id).Owner.Id));
        }
        public void Test_GetAllMeetings()
        {
            var usersRepository = new Mock<UsersRepository>(_connectionString) { CallBase = true };
            usersRepository.Setup(t => t.Get(It.IsAny<Guid>())).Returns(new User());

            var placesRepository = new Mock<PlacesRepository>(_connectionString) { CallBase = true };
            placesRepository.Setup(t => t.Get(It.IsAny<Guid>())).Returns(new Place());
            //arrange
            var meetingRepository = new MeetingsRepository(
                _connectionString,
                usersRepository.Object,
                placesRepository.Object
                );

            var owner1 = TestHelper.GenerateTestUser();
            meetingRepository.UsersRepository.Create(owner1);
            var place1 = TestHelper.GenerateTestPlace();
            meetingRepository.PlacesRepository.Create(place1);
            var meeting1 = new Meeting
            {
                Id = Guid.NewGuid(),
                Owner = owner1,
                Place = place1,
                Title = "titlemeet"
            };
            meetingRepository.Create(meeting1);

            var owner2 = TestHelper.GenerateTestUser();
            meetingRepository.UsersRepository.Create(owner2);
            var place2 = TestHelper.GenerateTestPlace();
            meetingRepository.PlacesRepository.Create(place2);
            var meeting2 = new Meeting
            {
                Id = Guid.NewGuid(),
                Owner = owner2,
                Place = place2,
                Title = "titlemeet"
            };
            meetingRepository.Create(meeting2);

            //act
            var meetings = meetingRepository.GetAllMeetings();
            //arrange
            Assert.IsTrue(meetings.Count() == 2);
        }
        public void Test_DeleteMember()
        {
            //arrange
            var meetingRepository = new MeetingsRepository(
                _connectionString,
                new UsersRepository(_connectionString),
                new PlacesRepository(_connectionString)
                );

            var user1 = TestHelper.GenerateTestUser(Guid.NewGuid());
            meetingRepository.UsersRepository.Create(user1);

            var owner = TestHelper.GenerateTestUser(Guid.NewGuid());
            meetingRepository.UsersRepository.Create(owner);

            var place = TestHelper.GenerateTestPlace(Guid.NewGuid());
            meetingRepository.PlacesRepository.Create(place);

            var meeting = new Meeting
            {
                Id = Guid.NewGuid(),
                Title = "title",
                Place = place,
                Owner = owner
            };
            meetingRepository.Create(meeting);

            meetingRepository.AddMember(meeting.Id, user1.Id);
            //act
            meetingRepository.DeleteMember(meeting.Id, user1.Id);
            //assert
            var members = meetingRepository.GetMembers(meeting.Id);
            Assert.IsFalse(members.Contains(user1));
        }
        public void Test_DeleteMeeting()
        {
            //arrange
            var meetingRepository = new MeetingsRepository(
                _connectionString,
                new UsersRepository(_connectionString),
                new PlacesRepository(_connectionString)
                );
            var user = TestHelper.GenerateTestUser(Guid.NewGuid());
            meetingRepository.UsersRepository.Create(user);

            var place = TestHelper.GenerateTestPlace(Guid.NewGuid());
            meetingRepository.PlacesRepository.Create(place);

            var meeting = new Meeting
            {
                Id = Guid.NewGuid(),
                Title = "title",
                Owner = user,
                Place = place

            };
            meetingRepository.Create(meeting);
            //act
            meetingRepository.Delete(meeting.Id);
            //asserts
            meetingRepository.Get(meeting.Id);
        }
        public void Test_CreateMeetingTwice()
        {
            //arrange
            var meetingRepository = new MeetingsRepository(
                _connectionString,
                new UsersRepository(_connectionString),
                new PlacesRepository(_connectionString)
                );

            var user = TestHelper.GenerateTestUser();
            meetingRepository.UsersRepository.Create(user);
            var place = TestHelper.GenerateTestPlace();
            meetingRepository.PlacesRepository.Create(place);
            var meeting = new Meeting
            {
                Id = Guid.NewGuid(),
                Owner = user,
                Place = place,
                Title = "titlemeet"
            };
            meetingRepository.Create(meeting);
            //act
            meetingRepository.Create(meeting);
        }