public void DeleteMeeting(Meeting meeting) { Log("Begin deleting Meeting from database. Meeting object ", meeting); DatabaseConnector.PushCommandToDatabase(sqlConnection, CommandList.Build_DeleteMeetingCommand(meeting)); Log("End deleting Meeting from database. Meeting object ", meeting); }
public static bool CompareMeetings(Meeting first, Meeting second) { return first.Id.Equals(second.Id) & first.Owner.Id.Equals(second.Owner.Id) & //first.Date.Equals(second.Date) & first.Title.Equals(second.Title) & first.Description.Equals(second.Description) & first.Place.Id.Equals(second.Place.Id); }
public static bool IsMeetingObjectExist(Meeting meeting, List<string> errorsList) { if (meeting == null) { errorsList.Add("Meeting object does not exist."); return false; } return true; }
public void CreateMeeting(Meeting meeting) { Log("Begin creating Meeting in database. Meeting object", meeting); DatabaseConnector.PushCommandToDatabase (sqlConnection, CommandList.Build_CreateMeetingCommand(meeting)); Log("End creating Meeting in database. Meeting object", meeting); }
public static List<string> IsCompleteValidMeetingObject(Meeting meeting) { List<string> errorsList = new List<string>(); if (!IsMeetingObjectExist(meeting, errorsList)) return errorsList; IsValidDateTime(meeting.Date, errorsList); IsValidTitle(meeting.Title, errorsList); IsValidDesription(meeting.Description, errorsList); return errorsList; }
public static SqlCommand Build_CreateMeetingCommand(Meeting meeting) { SqlCommand command = new SqlCommand(); Log("create meeting"); command.CommandText = "insert into [dbo].[Meeting] (ID, OwnerID, Date, Title, Description, PlaceID) " + "values (@Meeting_Id, @Meeting_OwnerID, @Meeting_Date, @Meeting_Title, @Meeting_Description, @Meeting_PlaceID);"; command.Parameters.AddWithValue("@Meeting_Id", meeting.Id); command.Parameters.AddWithValue("@Meeting_OwnerID", meeting.Owner.Id); command.Parameters.AddWithValue("@Meeting_Date", meeting.Date); command.Parameters.AddWithValue("@Meeting_Title", meeting.Title); command.Parameters.AddWithValue("@Meeting_Description", meeting.Description); command.Parameters.AddWithValue("@Meeting_PlaceID", meeting.Place.Id); Log("create meeting", command); return command; }
public IHttpActionResult Create(Meeting meeting) { Guid requestId = Guid.NewGuid(); Log("Received create meeting POST HTTP-request.", meeting, requestId); List<string> errorList = MeetDataValidator.IsCompleteValidMeetingObject(meeting); if (errorList.Count != 0) { Log("Send ErrorMessageResult(400) response to create meeting POST HTTP-request. " + "Message: Invalid model state.", requestId); return BadRequest("Invalid model state."); } if (_userRepository.GetUser(meeting.Owner.Id) == null) { Log("Send NotFoundWithMessageResult(404) response to create meeting POST HTTP-request." + "Message: Owner not found.", requestId); return new NotFoundWithMessageResult("Owner not found."); } if (_placeRepository.GetPlace(meeting.Place.Id) == null) { Log("Send NotFoundWithMessageResult(404) response to create meeting POST HTTP-request." + "Message: Place not found.", requestId); return new NotFoundWithMessageResult("Place not found."); } meeting.Id = Guid.NewGuid(); _meetRepository.CreateMeeting(meeting); Log("Send CreatedNegotiatedContentResult<Meeting>(201) response to create meeting POST HTTP-request.", meeting, requestId); return Created("", meeting); }
//[TestMethod] //public void InviteUserToMeeting_ShouldReturnOK() //{ // //arrange // Meeting meet = TestDataHelper.GenerateMeeting(); // User user = TestDataHelper.GenerateUser(); // var meetController = GetMeetingControlller(meet, meet.Owner, meet.Place); // //act // IHttpActionResult response = meetController.InviteUserToMeeting( // new Invitation // { // MeetingID = meet.Id, // UserID = user.Id // }); // //assert // Assert.IsTrue(response is OkResult); //} //[TestMethod] //public void InviteUserToMeeting_NonExistUser_ShouldNotFound() //{ // //arrange // Meeting meet = TestDataHelper.GenerateMeeting(); // User user = TestDataHelper.GenerateUser(); // var meetController = GetMeetingControlller(meet, null, meet.Place); // //act // IHttpActionResult response = meetController.InviteUserToMeeting( // new Invitation // { // MeetingID = meet.Id, // UserID = user.Id // }); // //assert // Assert.IsTrue(response is NotFoundWithMessageResult); //} //[TestMethod] //public void InviteUserToMeeting_NonExistMeet_ShouldNotFound() //{ // //arrange // //arrange // Meeting meet = TestDataHelper.GenerateMeeting(); // User user = TestDataHelper.GenerateUser(); // var meetController = GetMeetingControlller(null, meet.Owner, meet.Place); // //act // IHttpActionResult response = meetController.InviteUserToMeeting( // new Invitation // { // MeetingID = meet.Id, // UserID = user.Id // }); // //assert // Assert.IsTrue(response is NotFoundWithMessageResult); //} //[TestMethod] //public void InviteUserToMeeting_Alreadyinvited_ShouldReturnBadRequest() //{ // //arrange // Meeting meet = TestDataHelper.GenerateMeeting(); // User user = TestDataHelper.GenerateUser(); // var meetController = GetMeetingControlller(meet, meet.Owner, meet.Place); // //act // meet.InvitedPeople.Add(user.Id, user); // IHttpActionResult response = meetController.InviteUserToMeeting( // new Invitation // { // MeetingID = meet.Id, // UserID = user.Id // }); // //assert // Assert.IsTrue(response is BadRequestErrorMessageResult); //} MeetingController GetMeetingControlller(Meeting getMeetingResult, User getUserResult, Place getPlaceResult) { return new MeetingController( TestDataHelper.GetIMeetingRepositoryMock(getMeetingResult), TestDataHelper.GetIUserRepositoryMock(getUserResult), TestDataHelper.GetIPlaceRepositoryMock(getPlaceResult)); }
public static void PrintMeetingInfo(Meeting meeting) { Console.WriteLine("******Meeting info:"); Console.WriteLine("Id = " + meeting.Id); Console.WriteLine("Owner = " + meeting.Owner.Email); Console.WriteLine("Date = " + meeting.Date); Console.WriteLine("Title = " + meeting.Title); Console.WriteLine("Description = " + meeting.Description); Console.WriteLine("******Place info:"); Console.WriteLine("Id = " + meeting.Place.Id); Console.WriteLine("Address = " + meeting.Place.Address); Console.WriteLine("Description = " + meeting.Place.Description); Console.WriteLine("******Invited users:"); foreach(User user in meeting.InvitedPeople.Values) { Console.WriteLine(user.Email); } }
public static IMeetingRepository GetIMeetingRepositoryMock(Meeting getMeetingResult) { var mock = new Mock<IMeetingRepository>(); mock.Setup(meetingRepository => meetingRepository.GetMeeting(It.IsAny<Guid>())).Returns(getMeetingResult); return mock.Object; }
public static Meeting GenerateMeeting() { Meeting meeting = new Meeting { Id = Guid.NewGuid(), Owner = GenerateUser(), Date = DateTime.Now, Title = "Best test meeting #" + Index, Description = "Really best test meeting ever", Place = GeneratePlace(), InvitedPeople = new Dictionary<Guid, User>(), }; for (int i = 0; i < 5; i++) { User user = GenerateUser(); meeting.InvitedPeople.Add(user.Id, user); }; return meeting; }
public static Invitation CreateInvitation(Meeting meeting, User user) { return new Invitation { MeetingID = meeting.Id, UserID = user.Id }; }
public Task<HttpResponseMessage> Update(Meeting meeting) { return _crudHandler.Update(_controller, meeting); }
public static SqlCommand Build_UpdateMeetingCommand(Meeting meeting) { SqlCommand command = new SqlCommand(); Log("update meeting"); command.CommandText = "update [dbo].[Meeting] " + "SET Date = @Date, Title = @Title, Description = @Description " + "where id = @meetingId"; command.Parameters.AddWithValue("@meetingId", meeting.Id); //command.Parameters.AddWithValue("@OwnerID", meeting.Owner.Id); command.Parameters.AddWithValue("@Date", meeting.Date); command.Parameters.AddWithValue("@Title", meeting.Title); command.Parameters.AddWithValue("@Description", meeting.Description); //command.Parameters.AddWithValue("@PlaceID", meeting.Place.Id); Log("update meeting", command); return command; }
void Log(String logMessage, Meeting meeting, Guid requestId) { if (meeting != null) { _logger.Info("{5} {0} Attached meeting object: " + "ID = {1}, Title = {2}, Owner.ID = {3}, Place.ID = {4}.", logMessage, meeting.Id, meeting.Title, ((meeting.Owner == null) ? "null" : meeting.Owner.Id.ToString()), meeting.Place.Id, requestId); } else { _logger.Info("{1} Received {0} request. Attached meeting object is null.", logMessage, requestId); } }
InvitationController GetInvitationControlller(Meeting getMeetingResult, User getUserResult, bool IsExistInvitationResult) { return new InvitationController( TestDataHelper.GetIMeetingRepositoryMock(getMeetingResult), TestDataHelper.GetIUserRepositoryMock(getUserResult), TestDataHelper.GetIInvitationRepositoryMock(IsExistInvitationResult)); }
void Log(String logMessage, Meeting meeting) { if (meeting != null) { _logger.Debug("{0}: ID = {1}, Title = {2}, Owner.ID = {3}, Owner.Email = {4}, Place.ID = {5}, Place.Address = {6}, Place.Description = {7}.", logMessage, meeting.Id, meeting.Title, meeting.Owner.Id, meeting.Owner.Email, meeting.Place.Id, meeting.Place.Address, meeting.Place.Description); } else { _logger.Debug("{0} is null.", logMessage); } }
public void UpdateMeetingInfo(Meeting meeting) { Log("Begin updating Meeting in database. Meeting object ", meeting); DatabaseConnector.PushCommandToDatabase(sqlConnection, CommandList.Build_UpdateMeetingCommand(meeting)); Log("End updating Meeting in database. Meeting object ", meeting); }
void SetStartData() { _user = new User { FirstName = "Vasilyi", LastName = "Pupkin", Email = "*****@*****.**" }; _place = new Place { Address = "Puschkeen st., Kolotuschin h. #1", Description = "It is kolutushkin house." }; _meeting = new Meeting { Title = "Party", Description = "party description", Owner = new User(), Date = new DateTime(2016, 1, 1), Place = new Place(), InvitedPeople = new Dictionary<Guid, User>() }; }
public static SqlCommand Build_DeleteMeetingCommand(Meeting meeting) { SqlCommand command = new SqlCommand(); Log("delete meeting"); command.CommandText = "delete from [dbo].[Invitations] where MeetingID = @MeetingID; " + "delete from [dbo].[Meeting] where ID = @meetingID"; command.Parameters.AddWithValue("@meetingID", meeting.Id); Log("delete meeting", command); return command; }
public IHttpActionResult Update(Meeting meeting) { Guid requestId = Guid.NewGuid(); Log("Received update meeting PUT HTTP-request.", meeting, requestId); List<string> errorList = MeetDataValidator.IsCompleteValidMeetingObject(meeting); if (errorList.Count != 0) { Log("Send ErrorMessageResult(400) response to update meeting PUT HTTP-request. " + "Message: Invalid model state.", requestId); return BadRequest("Invalid model state."); } if (_meetRepository.GetMeeting(meeting.Id) == null) { Log("Send NotFoundResult(404) response to update meeting PUT HTTP-request.", requestId); return NotFound(); } _meetRepository.UpdateMeetingInfo(meeting); Log("Send CreatedNegotiatedContentResult<User>(201) response to update meeting PUT HTTP-request.", meeting, requestId); return Created("", meeting); }