Ejemplo n.º 1
0
        public void LoadSet_NotExistedFile_ReturnsFalseResult(string filePath)
        {
            // Arrange
            var fileValidator = new FileValidator(new ValidationData());
            var setService    = new SetService(fileValidator);
            var fileSource    = new EmbeddedSource(filePath, Assembly.GetExecutingAssembly());

            // Act
            void action() => setService.Load(fileSource);

            // Assert
            ResourceNotFoundException ex = Assert.Throws <ResourceNotFoundException>(action);
        }
Ejemplo n.º 2
0
        public void LoadSet_ValidationErrors_ReturnsFalseResult(
            List <string> filesPaths,
            List <Enum> errorCodes,
            List <Dictionary <string, string> > errorDetails)
        {
            // Arrange
            var fileValidator = new FileValidator(new ValidationData());
            var setService    = new SetService(fileValidator);
            var filesSources  = new List <ISource>();

            foreach (string filePath in filesPaths)
            {
                filesSources.Add(new EmbeddedSource(filePath, Assembly.GetExecutingAssembly()));
            }

            // Act
            OperationResult result = setService.Load(filesSources);

            // Assert
            Assert.False(result.Result);
            if (result.Errors == null)
            {
                throw new Exception("There are no expected errors.");
            }
            Assert.Equal(errorCodes.Count, result.Errors.Count);
            for (int i = 0; i < result.Errors.Count; i++)
            {
                if (result.Errors[i] is Error <Dictionary <string, string> > error)
                {
                    int errorCode = 0;
                    if (errorCodes[i] is Core.Models.ErrorCodesEnum coreErrorCode)
                    {
                        errorCode = (int)coreErrorCode;
                    }
                    if (errorCodes[i] is Words.Models.ErrorCodesEnum wordErrorCode)
                    {
                        errorCode = (int)wordErrorCode;
                    }
                    Assert.Equal(errorCode, error.Code);
                    foreach (KeyValuePair <string, string> el in errorDetails[i])
                    {
                        Assert.True(error.Data.ContainsKey(el.Key));
                        Assert.Equal(el.Value, error.Data[el.Key]);
                    }
                }
                else
                {
                    throw new Exception("Error is not Error<Dictionary<string, string>> type.");
                }
            }
        }