public void ReturnCorrectMessage_WhenCorrectParrametersArePassed() { var repository = new Mock <IRepository <Dictionary> >(); var unitOfWork = new Mock <IUnitOfWork>(); var userProvider = new Mock <IUserProvider>(); var dictionaryFactory = new Mock <IDictionariesFactory>(); string authorName = "Whoever"; string dictionaryTitle = "Vse Taq"; string languageName = "English"; User user = new User() { Username = authorName }; userProvider.Setup(u => u.LoggedUser).Returns(user); var language = new Language() { Name = languageName }; var dictionary = new Dictionary() { Author = authorName, Language = language, Title = dictionaryTitle }; dictionaryFactory.Setup(d => d.GetLanguage(languageName)).Returns(language); dictionaryFactory.Setup(d => d.GetDictionary(dictionaryTitle, authorName, language, It.IsAny <DateTime>())) .Returns(dictionary); var command = new CreateDictionaryCommand(repository.Object, unitOfWork.Object, userProvider.Object, dictionaryFactory.Object); var parameters = new List <string>() { dictionaryTitle, languageName }; string expectedResult = $"A new dictionary with title {dictionaryTitle}, author {authorName} and language {languageName} was created."; string result = command.Execute(parameters); Assert.AreEqual(expectedResult, result); }
public void SavesMadeChanges_WhenCorrectParrametersArePassed() { var repository = new Mock <IRepository <Dictionary> >(); var unitOfWork = new Mock <IUnitOfWork>(); var userProvider = new Mock <IUserProvider>(); var dictionaryFactory = new Mock <IDictionariesFactory>(); string authorName = "Whoever"; string dictionaryTitle = "Vse Taq"; string languageName = "English"; User user = new User() { Username = authorName }; userProvider.Setup(u => u.LoggedUser).Returns(user); var language = new Language() { Name = languageName }; var dictionary = new Dictionary() { Author = authorName, Language = language, Title = dictionaryTitle }; dictionaryFactory.Setup(d => d.GetLanguage(languageName)).Returns(language); dictionaryFactory.Setup(d => d.GetDictionary(dictionaryTitle, authorName, language, It.IsAny <DateTime>())) .Returns(dictionary); var command = new CreateDictionaryCommand(repository.Object, unitOfWork.Object, userProvider.Object, dictionaryFactory.Object); var parameters = new List <string>() { dictionaryTitle, languageName }; command.Execute(parameters); unitOfWork.Verify(r => r.SaveChanges(), Times.Once); }
public void Throw_WhenLessThanTwoParametersArePassed() { var repository = new Mock <IRepository <Dictionary> >(); var unitOfWork = new Mock <IUnitOfWork>(); var userProvider = new Mock <IUserProvider>(); var dictionaryFactory = new Mock <IDictionariesFactory>(); var command = new CreateDictionaryCommand(repository.Object, unitOfWork.Object, userProvider.Object, dictionaryFactory.Object); var parameters = new List <string>() { "wordName" }; Assert.Throws <ArgumentException>(() => command.Execute(parameters)); }
public void CreateDictionaryCommand_ExecuteRequest_1() { int returnCode = 0; Mock <IIrbisConnection> mock = GetConnectionMock(); IIrbisConnection connection = mock.Object; CreateDictionaryCommand command = new CreateDictionaryCommand(connection) { Database = "IBIS" }; ResponseBuilder builder = new ResponseBuilder() .StandardHeader(CommandCode.CreateDictionary, 123, 456) .NewLine() .Append(returnCode) .NewLine(); TestingSocket socket = (TestingSocket)connection.Socket; socket.Response = builder.Encode(); ClientQuery query = command.CreateQuery(); ServerResponse response = command.Execute(query); Assert.AreEqual(returnCode, response.ReturnCode); }