Beispiel #1
0
            public void GetDictionaryItemsExpectSuccess()
            {
                // Arrange
                const string CULTURE_CODE = "en";
                var dictionaryItems = new List<DictionaryItem>
                                          {
                                              new DictionaryItem
                                                  {
                                                      Code = "CB",
                                                      Name =
                                                          "Guest to be charged full booking value"
                                                  }
                                          };
                var dictionaryDao = MockRepository.GenerateStub<IDictionaryDao>();
                var dictionaryManager = new DictionaryManager() {DictionaryDao = dictionaryDao};
                dictionaryDao.Stub(
                    x => x.GetAllItemsWithCode(DictionaryItemKey.BookingCancellationRequestAction, CULTURE_CODE))
                             .Return(dictionaryItems);

                // Act
                dictionaryManager.GetAllItems(DictionaryItemKey.BookingCancellationRequestAction, CULTURE_CODE);

                // Assert
                dictionaryDao.VerifyAllExpectations();
            }
Beispiel #2
0
            public void GetDocumentTextByBusinessPopulatesReturnObjectCorrectly()
            {
                dictionaryManager.Setup(x => x.GetDictionaryItemByKeysAndCultures(new List<string>
            {
                DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_CANCELLATION,
                DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_CONFIRMATION,
                DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_GUESTREGISTRATION,
                DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_INVOICE
            }, new List<string>
            {
                "root"
            }))
                  .Returns(new List<DictionaryDataItem>
                  {
                      new DictionaryDataItem
                      {
                          ItemKey = DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_CONFIRMATION,
                          DictionaryInstances = new Collection<DictionaryInstance>
                          {
                              BusinessManager.GetBusinessDictionaryInstance("A", "root",
                                                                            DictionaryConstants
                                                                                .GUESTMESSAGE_CONFIRMATION, 1),
                          }
                      },
                      new DictionaryDataItem
                      {
                          ItemKey = DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_CANCELLATION,
                          DictionaryInstances = new Collection<DictionaryInstance>
                          {
                              BusinessManager.GetBusinessDictionaryInstance("B", "root",
                                                                            DictionaryConstants
                                                                                .GUESTMESSAGE_CANCELLATION, 1),
                          }
                      },
                      new DictionaryDataItem
                      {
                          ItemKey = DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_INVOICE,
                          DictionaryInstances = new Collection<DictionaryInstance>
                          {
                              BusinessManager.GetBusinessDictionaryInstance("C", "root",
                                                                            DictionaryConstants.GUESTMESSAGE_INVOICE, 1),
                          }
                      },
                      new DictionaryDataItem
                      {
                          ItemKey = DictionaryConstants.GUESTMESSAGE + 1 + DictionaryConstants.GUESTMESSAGE_GUESTREGISTRATION,
                          DictionaryInstances = new Collection<DictionaryInstance>
                          {
                              BusinessManager.GetBusinessDictionaryInstance("D", "root",
                                                                            DictionaryConstants
                                                                                .GUESTMESSAGE_GUESTREGISTRATION, 1)
                          }
                      }
                  });

                dictionaryManager.Setup(
                    x => x.DictionaryItemsToContent(It.IsAny<List<DictionaryDataItem>>(), It.IsAny<string>()))
                                 .Returns((List<DictionaryDataItem> dictionaryDataItems, string key)
                                          =>
                                     {
                                         var dm = new DictionaryManager();
                                         return
                                             dm.DictionaryItemsToContent(dictionaryDataItems, key
                                                 );
                                     });

                var documentText = businessManager.GetDocumentTextByBusiness(1, "root");

                Assert.AreEqual("A", documentText.Confirmation, "Unexpected value for Confirmation Text");
                Assert.AreEqual("B", documentText.Cancellation, "Unexpected value for Confirmation Text");
                Assert.AreEqual("C", documentText.Invoice, "Unexpected value for Confirmation Text");
                Assert.AreEqual("D", documentText.GuestRegistration, "Unexpected value for Confirmation Text");
                Assert.AreEqual("root", documentText.CultureCode, "Unexpected Value for Culture");
            }
Beispiel #3
0
            public void EmptyContentReturnsFalse()
            {
                // Arrange
                IDictionaryDao mockDao = MockRepository.GenerateMock<IDictionaryDao>();

                DictionaryInstance instance = new DictionaryInstance
                                                  {
                                                      Content = string.Empty,
                                                      CultureCode = VALID_CULTURE,
                                                      Item = new DictionaryDataItem
                                                      {
                                                          ItemKey = VALID_KEY
                                                      }
                                                  };

                // make sure we check before dao call
                mockDao.Expect(ddao => ddao.UpsertDictionaryInstance(Arg<DictionaryInstance>.Is.Anything))
                       .Repeat.Never();

                DictionaryManager manager = new DictionaryManager()
                    {
                        DictionaryDao = mockDao
                    };

                // Act
                bool response = manager.UpsertDictionaryInstance(instance);

                // Assert
                Assert.IsFalse(response, "Response should be false");
                mockDao.VerifyAllExpectations();
            }
Beispiel #4
0
            public void NoItemKeysThrowsException()
            {
                // Arrange
                // Act
                DictionaryManager manager = new DictionaryManager();

                manager.GetDictionaryItemByKeysAndCultures(null, null);
                // Assert done with expectedException
            }  
Beispiel #5
0
            public void MultiKeyNullCultureReturnsAllDictionaryItems()
            {
                // Arrange
                DictionaryDataItem mockDictItem1 = new DictionaryDataItem
                {
                    ItemKey = VALID_KEY,
                    RootCultureCode = ENGLISH_CULTURE,
                    DictionaryInstances = new List<DictionaryInstance>
                                                      {
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = ROOT_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = GERMAN_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = FRENCH_CULTURE,
                                                              Content = VALID_CONTENT
                                                          }
                                                      }
                };

                DictionaryDataItem mockDictItem2 = new DictionaryDataItem
                {
                    ItemKey = SECOND_VALID_KEY,
                    RootCultureCode = ENGLISH_CULTURE,
                    DictionaryInstances = new List<DictionaryInstance>
                                                      {
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = ROOT_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = GERMAN_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = FRENCH_CULTURE,
                                                              Content = VALID_CONTENT
                                                          }
                                                      }
                };

                CacheHelper.StubDictionaryCacheWithDictionaryItems(new List<DictionaryDataItem>{mockDictItem1, mockDictItem2});

                DictionaryManager manager = new DictionaryManager();

                // Act
                List<DictionaryDataItem> resultDictionaryDataItems = manager.GetDictionaryItemByKeysAndCultures(new List<string> { VALID_KEY, SECOND_VALID_KEY }, null);

                // Assert
                Assert.AreEqual(2, resultDictionaryDataItems.Count, "Number of dictionaries returned was incorrect");
                DictionaryDataItem resultDictionaryDataItem1 = resultDictionaryDataItems.First(di => di.ItemKey == VALID_KEY);
                DictionaryDataItem resultDictionaryDataItem2 = resultDictionaryDataItems.First(di => di.ItemKey == SECOND_VALID_KEY);

                Assert.AreEqual(mockDictItem1.ItemKey, resultDictionaryDataItem1.ItemKey, "Item key 1 was incorrect");
                Assert.AreEqual(mockDictItem1.RootCultureCode, resultDictionaryDataItem1.RootCultureCode,
                                "Root culture 1 was incorrect");
                Assert.AreEqual(mockDictItem1.DictionaryInstances.Count,
                                resultDictionaryDataItem1.DictionaryInstances.Count,
                                "Number of instances returned for 1 was not equal to what expected");

                Assert.AreEqual(mockDictItem2.ItemKey, resultDictionaryDataItem2.ItemKey, "Item key 2 was incorrect");
                Assert.AreEqual(mockDictItem2.RootCultureCode, resultDictionaryDataItem2.RootCultureCode,
                                "Root culture 2 was incorrect");
                Assert.AreEqual(mockDictItem2.DictionaryInstances.Count,
                                resultDictionaryDataItem2.DictionaryInstances.Count,
                                "Number of instances returned for 2 was not equal to what expected");

                CacheHelper.ReAssignDictionaryDaoToDictionaryCache();
            }
Beispiel #6
0
            public void SingleCultureSingleKeyReturnsSpecifiedCulture()
            {
                // Arrange
                DictionaryDataItem mockDictItem = new DictionaryDataItem
                {
                    ItemKey = VALID_KEY,
                    RootCultureCode = ENGLISH_CULTURE,
                    DictionaryInstances = new List<DictionaryInstance>
                                                      {
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = ROOT_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = GERMAN_CULTURE,
                                                              Content = VALID_CONTENT
                                                          },
                                                          new DictionaryInstance
                                                          {
                                                              CultureCode = FRENCH_CULTURE,
                                                              Content = VALID_CONTENT
                                                          }
                                                      }
                };

                CacheHelper.StubDictionaryCacheWithDictionaryItems(new List<DictionaryDataItem>{ mockDictItem});

                DictionaryManager manager = new DictionaryManager();
                // Act
                List<DictionaryDataItem> resultDictionaryDataItems = manager.GetDictionaryItemByKeysAndCultures(new List<string> { VALID_KEY }, new List<string> { GERMAN_CULTURE });

                // Assert
                Assert.AreEqual(1, resultDictionaryDataItems.Count, "Number of dictionaries returned was incorrect");
                DictionaryDataItem resultDictionaryDataItem = resultDictionaryDataItems[0];

                Assert.AreEqual(mockDictItem.ItemKey, resultDictionaryDataItem.ItemKey, "Item key was incorrect");
                Assert.AreEqual(mockDictItem.RootCultureCode, resultDictionaryDataItem.RootCultureCode,
                                "Root culture was incorrect");
                Assert.AreEqual(1, resultDictionaryDataItem.DictionaryInstances.Count,
                                "Number of instances returned was not equal to what expected");

                Assert.IsFalse(
                    resultDictionaryDataItem.DictionaryInstances.ToList().Exists(di => di.CultureCode == FRENCH_CULTURE),
                    "French culture was not filtered out");

                CacheHelper.ReAssignDictionaryDaoToDictionaryCache();
            }
Beispiel #7
0
            public void ValidDataCallsMethodsReturnsTrue()
            {
                // Arrange
                IDictionaryDao mockDao = MockRepository.GenerateMock<IDictionaryDao>();

                DictionaryInstance instance = new DictionaryInstance
                {
                    Content = VALID_CONTENT,
                    CultureCode = VALID_CULTURE,
                    Item = new DictionaryDataItem
                    {
                        ItemKey = VALID_KEY
                    }
                };

                // make sure we check before dao call
                mockDao.Expect(ddao => ddao.UpsertDictionaryInstance(Arg<DictionaryInstance>.Matches(dict => dict.Content == instance.Content &&
                                                                                                             dict.CultureCode == instance.CultureCode &&
                                                                                                             dict.Item.ItemKey == instance.Item.ItemKey))).Return(true).Repeat.Once();

                DictionaryManager manager = new DictionaryManager()
                {
                    DictionaryDao = mockDao
                };

                // Act
                bool response = manager.UpsertDictionaryInstance(instance);

                // Assert
                Assert.IsTrue(response, "Response should be true for good data");
                mockDao.VerifyAllExpectations();
            }