Monday, March 10, 2014

Moling HttpContext and Session in unit test

Code to mockup the HttpSessionState object, this would call the mole in place of httpsession and context.

using System.Web;
using System.Web.Moles;
using System.Web.SessionState;
using System.Web.SessionState.Moles;
using Microsoft.Moles.Framework;

 [TestClass]
    public class RoleTests
    {
        Dictionary sessionState = new Dictionary();

        [TestInitialize]
        public void Setup()
        {
            MHttpContext ct = new MHttpContext
            {
                SessionGet = () => new MHttpSessionState
                {
                    ItemGetString = (key) =>
                    {
                        if (key == "Roles")
                        {
                            if (sessionState.Count == 0)
                            {
                                sessionState[key] = new List();
                            }

                            return sessionState[key];
                        }
                        else return null;
                    }
                }
            };

            MHttpContext.CurrentGet = () =>
            {
                return ct;
            };
        }

}

Tuesday, September 22, 2009

Book for architect

97 Things Every Software Architect Should Know

Thursday, September 17, 2009

Loading large files as attachment in sql server

CREATE TABLE [dbo].[TEMP_ATTACH](
[DOCID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FILE_NAME] [varchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ATTACHMENT] [varbinary](max) NULL,
[FULL_NAME] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

declare @path varchar(100)
declare @filename Nvarchar(500)
SET @path = 'C:\Attachments\'
declare att_cursor cursor fast_forward for
select [full_name] from temp_attach

open att_cursor
fetch next from att_cursor into
@filename

while @@fetch_status = 0
begin

EXEC ('UPDATE TEMP_ATTACH
SET ATTACHMENT = BulkColumn
FROM OPENROWSET (BULK ''' + @path + @filename + ''', SINGLE_BLOB) MyFile
WHERE [full_name] = ''' + @filename + '''')

fetch next from att_cursor into
@filename
end
CLOSE att_cursor
DEALLOCATE att_cursor

Tuesday, March 10, 2009

remove all the options in the dropdown select box.

Use this JavaScript to remove all the options in the dropdown select box.

document.getElementById('Dropdown').length = 0;

Thursday, March 5, 2009

update a table from other table sql server

update Employee set email = lgfl.xx_email
from DB2.dbo.directEmployee lgfl join Employee on Employee.emp_name = lgfl.emp_name
where Employee.emp_id = dept.emp_id

Tuesday, January 27, 2009

GridView with BoundField which was setup to format date field with DataFormatString but string formatting is not working

html encoding is applied by default for the data before it is formatted. Therefore set HtmlEncode="false" to the BoundField so that formatting has expected effect.


http://aspadvice.com/blogs/joteke/archive/2005/09/25/12871.aspx


http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topic24899.aspx

Wednesday, November 19, 2008

Finding maximum characters for each filed in a table

DECLARE
@c varchar(4000),
@t varchar(128),
@maxchars int,
@fieldName varchar(100),
@dynamicSql nvarchar(2000)
SET @c = ''
SET @t='LEGACY_GMM'
SET @maxchars = 0
SET @fieldName = ''
SET @dynamicSql = ''
SELECT @c = @c + c.name + ', '
FROM syscolumns c
INNER JOIN sysobjects o ON o.id = c.id
WHERE o.name = 'LEGACY_GMM' and c.colorder < 101
while charindex(',', @c) > 0
begin
SET @fieldName = substring(@c,0,charindex(',',@c))
SET @dynamicSql = 'select max(len(' + @fieldName + ')) as ' + @fieldName + ' from LEGACY_GMM;'
execute sp_executesql @dynamicSql
SET @c = substring(@c, charindex(',',@c)+1, LEN(@c))
end