public void GetAllDeals_ShouldReturnDeals() { var dealsTestData = new List <DealViewDTO>() { new DealViewDTO { Id = Guid.NewGuid() }, new DealViewDTO { Id = Guid.NewGuid() }, new DealViewDTO { Id = Guid.NewGuid() } }; var cars = MockHelper.MockDbSet(dealsTestData); var dbContext = new Mock <IAppDbContext>(); dbContext.Setup(d => d.ExecuteStoredProcedure <DealViewDTO>(It.IsAny <string>(), It.IsAny <object[]>())) .Returns <string, object[]>((query, parameters) => { List <DealViewDTO> list = new List <DealViewDTO>(); if (query.Contains("DealsFilter")) { list.Add(new DealViewDTO { Id = Guid.NewGuid() }); list.Add(new DealViewDTO { Id = Guid.NewGuid() }); list.Add(new DealViewDTO { Id = Guid.NewGuid() }); } else { list.Add(new DealViewDTO { Id = Guid.NewGuid() }); } return(list); }); var factory = new Mock <IDbContextFactory>(); factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object); var controller = new DealsController(factory.Object); var result = controller.GetDeals(1, DateTime.Now, DateTime.Now) as OkNegotiatedContentResult <IEnumerable <DealViewDTO> >; Assert.IsNotNull(result); Assert.AreEqual(3, result.Content.Count()); }
public void Main() { try { while (true) { var messageType = (MessageType)_BinaryFormatter.Deserialize(_NetworkStream); if (messageType == MessageType.Action) { var actionType = (ActionType)_BinaryFormatter.Deserialize(_NetworkStream); switch (actionType) { case ActionType.Authorize: UserController.Authorize(); break; case ActionType.Register: UserController.Register(); break; case ActionType.GetAutodealers: AutodealerController.GetAutodealers(); break; case ActionType.SetCurrentAutodealer: AutodealerController.SetCurrentAutodealer(); break; case ActionType.GetCars: CarController.GetCars(); break; case ActionType.GetCurrentUser: UserController.GetCurrentUser(); break; case ActionType.GetCurrentAutodealer: AutodealerController.GetCurrentAutodealer(); break; case ActionType.AddCar: CarController.Add(); break; case ActionType.DeleteCar: CarController.Delete(); break; case ActionType.EditCar: CarController.Edit(); break; case ActionType.SetCarFilter: CarController.SetCarFilter(); break; case ActionType.ResetCarFilter: CarController.ResetCarFilter(); break; case ActionType.GetUsers: UserController.GetUsers(); break; case ActionType.AddUser: UserController.Add(); break; case ActionType.BanUnbanUser: UserController.BanUnbanUser(); break; case ActionType.DeleteUser: UserController.Delete(); break; case ActionType.SetUserSearchData: UserController.SetUserSearchData(); break; case ActionType.EditUser: UserController.Edit(); break; case ActionType.GetDeals: DealsController.GetDeals(); break; case ActionType.ConfirmDeal: DealsController.ConfirmDeal(); break; case ActionType.DeleteDeal: DealsController.Delete(); break; case ActionType.AddDeal: DealsController.Add(); break; case ActionType.EditDeal: DealsController.Edit(); break; case ActionType.SetDealSearchData: DealsController.SetDealSearchData(); break; case ActionType.DeleteAutodealer: AutodealerController.Delete(); break; case ActionType.AddAutodealer: AutodealerController.Add(); break; case ActionType.EditAutodealer: AutodealerController.Edit(); break; case ActionType.SetAutodealerSearchData: AutodealerController.SetAutodealerSearchData(); break; case ActionType.GetCurrentAutodealerStatistics: StatisticsController.GetCurrentAutodealerStatistics(); break; case ActionType.GetNotSoldCars: CarController.GetNotSoldCars(); break; case ActionType.EditCurrentUserUsername: UserController.EditCurrentUserUsername(); break; case ActionType.EditCurrentUserPassword: UserController.EditCurrentUserPassword(); break; case ActionType.EditCurrentUserFirstname: UserController.EditCurrentUserFirstname(); break; case ActionType.EditCurrentUserSurname: UserController.EditCurrentUserSurname(); break; case ActionType.EditCurrentUserTelephone: UserController.EditCurrentUserTelephone(); break; case ActionType.BuyCar: CarController.BuyCar(); break; case ActionType.GetCurrentUserStatistics: DealsController.GetCurrentUserStatistics(); break; case ActionType.GetCurrentUserCars: CarController.GetCurrentUserCars(); break; case ActionType.GetUsersNotSuperUsers: UserController.GetUsersNotSuperUsers(); break; } } } } catch (Exception) {} finally { if (_NetworkStream != null) { _NetworkStream.Close(); } if (Client != null) { Client.Close(); } } }